Skip to content

Commit 41ebbbb

Browse files
authored
docs: improve missing data error (#3406)
1 parent dce28d6 commit 41ebbbb

File tree

5 files changed

+10
-3
lines changed

5 files changed

+10
-3
lines changed

docs/guide/localization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,11 @@ As a workaround, you can provide additional fallbacks to your `Faker` instance:
181181

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

186186
const faker = new Faker({
187187
locale: [el], // [!code --]
188-
locale: [el, en], // [!code ++]
188+
locale: [el, en, base], // [!code ++]
189189
});
190190
console.log(faker.location.country()); // 'Belgium'
191191
```

src/faker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ export class Faker extends SimpleFaker {
120120
* For more information see our [Localization Guide](https://fakerjs.dev/guide/localization.html).
121121
*
122122
* @param options The options to use.
123-
* @param options.locale The locale data to use.
123+
* @param options.locale The locale data to use for this instance.
124+
* If an array is provided, the first locale that has a definition for a given property will be used.
125+
* Please make sure that all required locales and their parent locales are present, e.g. `[de_AT, de, en, base]`.
124126
* @param options.randomizer The Randomizer to use.
125127
* Specify this only if you want to use it to achieve a specific goal,
126128
* such as sharing the same random generator with other instances/tools.
@@ -148,6 +150,7 @@ export class Faker extends SimpleFaker {
148150
/**
149151
* The locale data to use for this instance.
150152
* If an array is provided, the first locale that has a definition for a given property will be used.
153+
* Please make sure that all required locales and their parent locales are present, e.g. `[de_AT, de, en, base]`.
151154
*
152155
* @see mergeLocales(): For more information about how the locales are merged.
153156
*/

src/internal/locale-proxy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export function assertLocaleData<T>(
7272
} else if (value === undefined) {
7373
throw new FakerError(
7474
`The locale data for '${path.join('.')}' are missing in this locale.
75+
If this is a custom Faker instance, please make sure all required locales are used e.g. '[de_AT, de, en, base]'.
7576
Please contribute the missing data to the project or use a locale/Faker instance that has these data.
7677
For more information see https://fakerjs.dev/guide/localization.html`
7778
);

test/internal/locale-proxy.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ describe('LocaleProxy', () => {
9797
expect(() => locale.category.missing).toThrow(
9898
new FakerError(
9999
`The locale data for 'category.missing' are missing in this locale.
100+
If this is a custom Faker instance, please make sure all required locales are used e.g. '[de_AT, de, en, base]'.
100101
Please contribute the missing data to the project or use a locale/Faker instance that has these data.
101102
For more information see https://fakerjs.dev/guide/localization.html`
102103
)
@@ -107,6 +108,7 @@ describe('LocaleProxy', () => {
107108
expect(() => locale.airline.missing).toThrow(
108109
new FakerError(
109110
`The locale data for 'airline.missing' are missing in this locale.
111+
If this is a custom Faker instance, please make sure all required locales are used e.g. '[de_AT, de, en, base]'.
110112
Please contribute the missing data to the project or use a locale/Faker instance that has these data.
111113
For more information see https://fakerjs.dev/guide/localization.html`
112114
)

test/modules/location.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ describe('location', () => {
220220
expect(() => faker.location.zipCode({ state: 'XX' })).toThrow(
221221
new FakerError(
222222
`The locale data for 'location.postcode_by_state' are missing in this locale.
223+
If this is a custom Faker instance, please make sure all required locales are used e.g. '[de_AT, de, en, base]'.
223224
Please contribute the missing data to the project or use a locale/Faker instance that has these data.
224225
For more information see https://fakerjs.dev/guide/localization.html`
225226
)

0 commit comments

Comments
 (0)