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

docs: improve missing data error #3406

Merged
merged 6 commits into from
Feb 28, 2025
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
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