Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Remove warning message in production #13911

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/x-charts/src/BarChart/checkScaleErrors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('BarChart - checkScaleErrors', () => {
},
);
}).throws(
'MUI X Charts: The first `xAxis` should be of type "band" to display the bar series of id "seriesId".',
'MUI X: The first `xAxis` should be of type "band" to display the bar series of id "seriesId".',
);
});

Expand All @@ -43,7 +43,7 @@ describe('BarChart - checkScaleErrors', () => {
[yKey]: { id: yKey, scaleType: 'linear' },
},
);
}).throws('MUI X Charts: The first `xAxis` should have data property.');
}).throws('MUI X: The first `xAxis` should have data property.');
});

it('should throw an error when the y-axis is not a continuous scale', () => {
Expand All @@ -64,7 +64,7 @@ describe('BarChart - checkScaleErrors', () => {
},
);
}).throws(
'MUI X Charts: The first `yAxis` should be a continuous type to display the bar series of id "seriesId".',
'MUI X: The first `yAxis` should be a continuous type to display the bar series of id "seriesId".',
);
});

Expand Down Expand Up @@ -108,7 +108,7 @@ describe('BarChart - checkScaleErrors', () => {
},
);
}).throws(
'MUI X Charts: The first `yAxis` should be of type "band" to display the bar series of id "seriesId".',
'MUI X: The first `yAxis` should be of type "band" to display the bar series of id "seriesId".',
);
});

Expand All @@ -129,7 +129,7 @@ describe('BarChart - checkScaleErrors', () => {
[yKey]: { id: yKey, scaleType: 'band' },
},
);
}).throws('MUI X Charts: The first `yAxis` should have data property.');
}).throws('MUI X: The first `yAxis` should have data property.');
});

it('should throw an error when the x-axis is not a continuous scale', () => {
Expand All @@ -150,7 +150,7 @@ describe('BarChart - checkScaleErrors', () => {
},
);
}).throws(
'MUI X Charts: The first `xAxis` should be a continuous type to display the bar series of id "seriesId".',
'MUI X: The first `xAxis` should be a continuous type to display the bar series of id "seriesId".',
);
});

Expand Down Expand Up @@ -193,7 +193,7 @@ describe('BarChart - checkScaleErrors', () => {
},
);
}).throws(
'MUI X Charts: The x-axis with id "x-test" should be of type "band" to display the bar series of id "seriesId".',
'MUI X: The x-axis with id "x-test" should be of type "band" to display the bar series of id "seriesId".',
);
});

Expand All @@ -215,7 +215,7 @@ describe('BarChart - checkScaleErrors', () => {
},
);
}).throws(
'MUI X Charts: The y-axis with id "y-test" should be of type "band" to display the bar series of id "seriesId".',
'MUI X: The y-axis with id "y-test" should be of type "band" to display the bar series of id "seriesId".',
);
});
});
6 changes: 3 additions & 3 deletions packages/x-charts/src/BarChart/checkScaleErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ export function checkScaleErrors(

if (!isBandScaleConfig(discreteAxisConfig)) {
throw new Error(
`MUI X Charts: ${getAxisMessage(discreteAxisDirection, discreteAxisKey)} should be of type "band" to display the bar series of id "${seriesId}".`,
`MUI X: ${getAxisMessage(discreteAxisDirection, discreteAxisKey)} should be of type "band" to display the bar series of id "${seriesId}".`,
);
}
if (discreteAxisConfig.data === undefined) {
throw new Error(
`MUI X Charts: ${getAxisMessage(discreteAxisDirection, discreteAxisKey)} should have data property.`,
`MUI X: ${getAxisMessage(discreteAxisDirection, discreteAxisKey)} should have data property.`,
);
}
if (isBandScaleConfig(continuousAxisConfig) || isPointScaleConfig(continuousAxisConfig)) {
throw new Error(
`MUI X Charts: ${getAxisMessage(continuousAxisDirection, continuousAxisKey)} should be a continuous type to display the bar series of id "${seriesId}".`,
`MUI X: ${getAxisMessage(continuousAxisDirection, continuousAxisKey)} should be a continuous type to display the bar series of id "${seriesId}".`,
);
}
}
12 changes: 7 additions & 5 deletions packages/x-charts/src/BarChart/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const formatter: Formatter<'bar'> = (params, dataset) => {
} else if (dataset === undefined) {
throw new Error(
[
`MUI X Charts: bar series with id='${id}' has no data.`,
`MUI X: bar series with id='${id}' has no data.`,
'Either provide a data property to the series or use the dataset prop.',
].join('\n'),
);
Expand Down Expand Up @@ -69,10 +69,12 @@ const formatter: Formatter<'bar'> = (params, dataset) => {
if (typeof value !== 'number') {
if (process.env.NODE_ENV !== 'production' && !warnOnce && value !== null) {
warnOnce = true;
console.error([
`MUI X charts: your dataset key "${dataKey}" is used for plotting bars, but contains nonnumerical elements.`,
'Bar plots only support numbers and null values.',
]);
console.error(
[
`MUI X charts: your dataset key "${dataKey}" is used for plotting bars, but contains nonnumerical elements.`,
'Bar plots only support numbers and null values.',
].join('\n'),
);
}
return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/x-charts/src/ChartsAxis/ChartsAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,31 +99,31 @@ function ChartsAxis(props: ChartsAxisProps) {
if (topId !== null && !xAxis[topId]) {
throw Error(
[
`MUI X Charts: id used for top axis "${topId}" is not defined.`,
`MUI X: id used for top axis "${topId}" is not defined.`,
`Available ids are: ${xAxisIds.join(', ')}.`,
].join('\n'),
);
}
if (leftId !== null && !yAxis[leftId]) {
throw Error(
[
`MUI X Charts: id used for left axis "${leftId}" is not defined.`,
`MUI X: id used for left axis "${leftId}" is not defined.`,
`Available ids are: ${yAxisIds.join(', ')}.`,
].join('\n'),
);
}
if (rightId !== null && !yAxis[rightId]) {
throw Error(
[
`MUI X Charts: id used for right axis "${rightId}" is not defined.`,
`MUI X: id used for right axis "${rightId}" is not defined.`,
`Available ids are: ${yAxisIds.join(', ')}.`,
].join('\n'),
);
}
if (bottomId !== null && !xAxis[bottomId]) {
throw Error(
[
`MUI X Charts: id used for bottom axis "${bottomId}" is not defined.`,
`MUI X: id used for bottom axis "${bottomId}" is not defined.`,
`Available ids are: ${xAxisIds.join(', ')}.`,
].join('\n'),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function ChartsAxisHighlight(props: ChartsAxisHighlightProps) {
if (isXError || isYError) {
console.error(
[
`MUI X Charts: The position value provided for the axis is not valid for the current scale.`,
`MUI X: The position value provided for the axis is not valid for the current scale.`,
`This probably means something is wrong with the data passed to the chart.`,
`The ChartsAxisHighlight component will not be displayed.`,
].join('\n'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ type ChartsReferenceLineProps<TValue extends string | number | Date = string | n
function ChartsReferenceLine(props: ChartsReferenceLineProps) {
const { x, y } = props;
if (x !== undefined && y !== undefined) {
throw new Error(
'MUI X Charts: The ChartsReferenceLine cannot have both `x` and `y` props set.',
);
throw new Error('MUI X: The ChartsReferenceLine cannot have both `x` and `y` props set.');
}

if (x === undefined && y === undefined) {
throw new Error(
'MUI X Charts: The ChartsReferenceLine should have a value in `x` or `y` prop.',
);
throw new Error('MUI X: The ChartsReferenceLine should have a value in `x` or `y` prop.');
}

if (x !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ChartsReferenceLineClasses,
getReferenceLineUtilityClass,
} from './chartsReferenceLineClasses';
import { buildWarning } from '../internals/warning';
import { warnOnce } from '../internals/warning';

export type ChartsXReferenceLineProps<
TValue extends string | number | Date = string | number | Date,
Expand Down Expand Up @@ -73,12 +73,6 @@ export function getXReferenceLineClasses(classes?: Partial<ChartsReferenceLineCl
);
}

const valueError = buildWarning(
(value, id) =>
`MUI X Charts: the value ${value} does not exist in the data of x axis with id ${id}.`,
'error',
);

function ChartsXReferenceLine(props: ChartsXReferenceLineProps) {
const {
x,
Expand All @@ -98,7 +92,10 @@ function ChartsXReferenceLine(props: ChartsXReferenceLineProps) {

if (xPosition === undefined) {
if (process.env.NODE_ENV !== 'production') {
valueError(x, axisId);
warnOnce(
`MUI X: the value ${x} does not exist in the data of x axis with id ${axisId}.`,
'error',
);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ChartsReferenceLineClasses,
getReferenceLineUtilityClass,
} from './chartsReferenceLineClasses';
import { buildWarning } from '../internals/warning';
import { warnOnce } from '../internals/warning';

export type ChartsYReferenceLineProps<
TValue extends string | number | Date = string | number | Date,
Expand Down Expand Up @@ -73,12 +73,6 @@ export function getYReferenceLineClasses(classes?: Partial<ChartsReferenceLineCl
);
}

const valueError = buildWarning(
(value, id) =>
`MUI X Charts: the value ${value} does not exist in the data of y axis with id ${id}.`,
'error',
);

function ChartsYReferenceLine(props: ChartsYReferenceLineProps) {
const {
y,
Expand All @@ -98,7 +92,10 @@ function ChartsYReferenceLine(props: ChartsYReferenceLineProps) {

if (yPosition === undefined) {
if (process.env.NODE_ENV !== 'production') {
valueError(y, axisId);
warnOnce(
`MUI X: the value ${y} does not exist in the data of y axis with id ${axisId}.`,
'error',
);
}
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/LineChart/AreaPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const useAggregatedData = () => {
if (process.env.NODE_ENV !== 'production') {
if (xData === undefined) {
throw new Error(
`MUI X Charts: ${
`MUI X: ${
xAxisKey === DEFAULT_X_AXIS_KEY
? 'The first `xAxis`'
: `The x-axis with id "${xAxisKey}"`
Expand All @@ -80,7 +80,7 @@ const useAggregatedData = () => {
}
if (xData.length < stackedData.length) {
throw new Error(
`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`,
`MUI X: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/x-charts/src/LineChart/LineHighlightPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function LineHighlightPlot(props: LineHighlightPlotProps) {

if (xData === undefined) {
throw new Error(
`MUI X Charts: ${
`MUI X: ${
xAxisKey === DEFAULT_X_AXIS_KEY
? 'The first `xAxis`'
: `The x-axis with id "${xAxisKey}"`
Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/LineChart/LinePlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const useAggregatedData = () => {
if (process.env.NODE_ENV !== 'production') {
if (xData === undefined) {
throw new Error(
`MUI X Charts: ${
`MUI X: ${
xAxisKey === DEFAULT_X_AXIS_KEY
? 'The first `xAxis`'
: `The x-axis with id "${xAxisKey}"`
Expand All @@ -78,7 +78,7 @@ const useAggregatedData = () => {
}
if (xData.length < stackedData.length) {
throw new Error(
`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`,
`MUI X: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/x-charts/src/LineChart/MarkPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function MarkPlot(props: MarkPlotProps) {

if (xData === undefined) {
throw new Error(
`MUI X Charts: ${
`MUI X: ${
xAxisKey === DEFAULT_X_AXIS_KEY
? 'The first `xAxis`'
: `The x-axis with id "${xAxisKey}"`
Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/LineChart/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const formatter: Formatter<'line'> = (params, dataset) => {
} else if (dataset === undefined && process.env.NODE_ENV !== 'production') {
throw new Error(
[
`MUI X Charts: line series with id='${id}' has no data.`,
`MUI X: line series with id='${id}' has no data.`,
'Either provide a data property to the series or use the dataset prop.',
].join('\n'),
);
Expand Down Expand Up @@ -67,7 +67,7 @@ const formatter: Formatter<'line'> = (params, dataset) => {
if (process.env.NODE_ENV !== 'production' && !warnedOnce && value !== null) {
warnedOnce = true;
console.error([
`MUI X charts: your dataset key "${dataKey}" is used for plotting line, but contains nonnumerical elements.`,
`MUI X: Your dataset key "${dataKey}" is used for plotting line, but contains nonnumerical elements.`,
'Line plots only support numbers and null values.',
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ export const useChartContainerDimensions = (inWidth?: number, inHeight?: number)
if (process.env.NODE_ENV !== 'production') {
if (displayError.current && inWidth === undefined && width === 0) {
console.error(
`MUI X Charts: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`,
`MUI X: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`,
);
displayError.current = false;
}
if (displayError.current && inHeight === undefined && height === 0) {
console.error(
`MUI X Charts: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`,
`MUI X: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`,
);
displayError.current = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ export const normalizeAxis = <
return axisConfig;
}
if (dataset === undefined) {
throw Error(
`MUI X Charts: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`,
);
throw Error(`MUI X: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`);
}
return {
...axisConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/x-charts/src/context/SeriesContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const preprocessSeries = <T extends ChartSeriesType>(
seriesGroups[type] = { series: {}, seriesOrder: [] };
}
if (seriesGroups[type]?.series[id] !== undefined) {
throw new Error(`MUI X Charts: series' id "${id}" is not unique.`);
throw new Error(`MUI X: series' id "${id}" is not unique.`);
}

seriesGroups[type]!.series[id] = {
Expand Down
2 changes: 1 addition & 1 deletion packages/x-charts/src/context/ZAxisContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function ZAxisContextProvider(props: ZAxisContextProviderProps) {
return axisConfig;
}
if (dataset === undefined) {
throw Error('MUI X Charts: z-axis uses `dataKey` but no `dataset` is provided.');
throw Error('MUI X: z-axis uses `dataKey` but no `dataset` is provided.');
}
return {
...axisConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/x-charts/src/internals/geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function getMinXTranslation(width: number, height: number, angle: number
warnedOnce = true;
console.warn(
[
`MUI X Charts: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`,
`MUI X: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`,
`This could cause some text overlapping.`,
`If you encounter a use case where it's needed, please open an issue.`,
].join('\n'),
Expand Down
2 changes: 1 addition & 1 deletion packages/x-charts/src/internals/getPercentageValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export function getPercentageValue(value: number | string, refValue: number) {
}
}
throw Error(
`MUI X Charts: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`,
`MUI X: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`,
);
}
Loading
Loading