Skip to content

Commit

Permalink
fix: Change error messages to not mention provider (since there might…
Browse files Browse the repository at this point in the history
… be none) (#1589)
  • Loading branch information
amannn authored Dec 2, 2024
1 parent cb6b998 commit 8f37883
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/use-intl/src/core/createBaseTranslator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function getMessagesOrError<Messages extends AbstractIntlMessages>(
if (!messages) {
throw new Error(
process.env.NODE_ENV !== 'production'
? `No messages were configured on the provider.`
? `No messages were configured.`
: undefined
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/use-intl/src/core/createFormatter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default function createFormatter(props: Props) {
const error = new IntlError(
IntlErrorCode.MISSING_FORMAT,
process.env.NODE_ENV !== 'production'
? `Format \`${formatName}\` is not available. You can configure it on the provider or provide custom options.`
? `Format \`${formatName}\` is not available.`
: undefined
);
onError(error);
Expand Down
6 changes: 3 additions & 3 deletions packages/use-intl/src/react/useFormatter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ describe('dateTime', () => {

const error: IntlError = onError.mock.calls[0][0];
expect(error.message).toBe(
'MISSING_FORMAT: Format `onlyYear` is not available. You can configure it on the provider or provide custom options.'
'MISSING_FORMAT: Format `onlyYear` is not available.'
);
expect(error.code).toBe(IntlErrorCode.MISSING_FORMAT);
expect(container.textContent).toMatch(/Nov 20 2020/);
Expand All @@ -234,7 +234,7 @@ describe('dateTime', () => {

const error: IntlError = onError.mock.calls[0][0];
expect(error.message).toBe(
'MISSING_FORMAT: Format `medium` is not available. You can configure it on the provider or provide custom options.'
'MISSING_FORMAT: Format `medium` is not available.'
);
expect(error.code).toBe(IntlErrorCode.MISSING_FORMAT);
expect(container.textContent).toMatch(/Nov 20 2020/);
Expand Down Expand Up @@ -397,7 +397,7 @@ describe('number', () => {

const error: IntlError = onError.mock.calls[0][0];
expect(error.message).toBe(
'MISSING_FORMAT: Format `missing` is not available. You can configure it on the provider or provide custom options.'
'MISSING_FORMAT: Format `missing` is not available.'
);
expect(error.code).toBe(IntlErrorCode.MISSING_FORMAT);
expect(container.textContent).toBe('10000');
Expand Down
4 changes: 1 addition & 3 deletions packages/use-intl/src/react/useTranslations.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,7 @@ describe('error handling', () => {
expect(onError).toHaveBeenCalledTimes(1);
const error: IntlError = onError.mock.calls[0][0];
expect(error.code).toBe(IntlErrorCode.MISSING_MESSAGE);
expect(error.message).toBe(
'MISSING_MESSAGE: No messages were configured on the provider.'
);
expect(error.message).toBe('MISSING_MESSAGE: No messages were configured.');
screen.getByText('Component.test');
});

Expand Down

0 comments on commit 8f37883

Please sign in to comment.