Skip to content

Commit

Permalink
docs: improve missing data error (#3406)
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Feb 28, 2025
1 parent dce28d6 commit 41ebbbb
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/guide/localization.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ As a workaround, you can provide additional fallbacks to your `Faker` instance:

```ts
import { Faker, el } from '@faker-js/faker'; // [!code --]
import { Faker, el, en } from '@faker-js/faker'; // [!code ++]
import { Faker, base, el, en } from '@faker-js/faker'; // [!code ++]

const faker = new Faker({
locale: [el], // [!code --]
locale: [el, en], // [!code ++]
locale: [el, en, base], // [!code ++]
});
console.log(faker.location.country()); // 'Belgium'
```
Expand Down
5 changes: 4 additions & 1 deletion src/faker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ export class Faker extends SimpleFaker {
* For more information see our [Localization Guide](https://fakerjs.dev/guide/localization.html).
*
* @param options The options to use.
* @param options.locale The locale data to use.
* @param options.locale The locale data to use for this instance.
* If an array is provided, the first locale that has a definition for a given property will be used.
* Please make sure that all required locales and their parent locales are present, e.g. `[de_AT, de, en, base]`.
* @param options.randomizer The Randomizer to use.
* Specify this only if you want to use it to achieve a specific goal,
* such as sharing the same random generator with other instances/tools.
Expand Down Expand Up @@ -148,6 +150,7 @@ export class Faker extends SimpleFaker {
/**
* The locale data to use for this instance.
* If an array is provided, the first locale that has a definition for a given property will be used.
* Please make sure that all required locales and their parent locales are present, e.g. `[de_AT, de, en, base]`.
*
* @see mergeLocales(): For more information about how the locales are merged.
*/
Expand Down
1 change: 1 addition & 0 deletions src/internal/locale-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export function assertLocaleData<T>(
} else if (value === undefined) {
throw new FakerError(
`The locale data for '${path.join('.')}' are missing in this locale.
If this is a custom Faker instance, please make sure all required locales are used e.g. '[de_AT, de, en, base]'.
Please contribute the missing data to the project or use a locale/Faker instance that has these data.
For more information see https://fakerjs.dev/guide/localization.html`
);
Expand Down
2 changes: 2 additions & 0 deletions test/internal/locale-proxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ describe('LocaleProxy', () => {
expect(() => locale.category.missing).toThrow(
new FakerError(
`The locale data for 'category.missing' are missing in this locale.
If this is a custom Faker instance, please make sure all required locales are used e.g. '[de_AT, de, en, base]'.
Please contribute the missing data to the project or use a locale/Faker instance that has these data.
For more information see https://fakerjs.dev/guide/localization.html`
)
Expand All @@ -107,6 +108,7 @@ describe('LocaleProxy', () => {
expect(() => locale.airline.missing).toThrow(
new FakerError(
`The locale data for 'airline.missing' are missing in this locale.
If this is a custom Faker instance, please make sure all required locales are used e.g. '[de_AT, de, en, base]'.
Please contribute the missing data to the project or use a locale/Faker instance that has these data.
For more information see https://fakerjs.dev/guide/localization.html`
)
Expand Down
1 change: 1 addition & 0 deletions test/modules/location.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ describe('location', () => {
expect(() => faker.location.zipCode({ state: 'XX' })).toThrow(
new FakerError(
`The locale data for 'location.postcode_by_state' are missing in this locale.
If this is a custom Faker instance, please make sure all required locales are used e.g. '[de_AT, de, en, base]'.
Please contribute the missing data to the project or use a locale/Faker instance that has these data.
For more information see https://fakerjs.dev/guide/localization.html`
)
Expand Down

0 comments on commit 41ebbbb

Please sign in to comment.