-
-
Notifications
You must be signed in to change notification settings - Fork 944
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
County
method used with uniqueArray
helper crashes faker.
#2207
Comments
There are not 20 different unique counties in the default en locale. Try using a different locale eg en_US or en_GB. |
I wonder if uniqueArray should have some logic where when passed a method, it aborts if it has tried generating say 1000x the requested number of items in the array. |
The array part is safe. faker/src/modules/helpers/index.ts Lines 673 to 677 in 631f732
That can be used as a workaround. But for the function input we have to add the max retry logic. faker/src/modules/helpers/index.ts Lines 679 to 690 in 631f732
|
per #1944 we should also do something about the https://github.com/faker-js/faker/blob/next/src/locales/en/location/county.ts file - either remove it (and have it throw an error), or replace it with more realistic data like https://github.com/faker-js/faker/blob/next/src/locales/en_US/location/county.ts or https://github.com/faker-js/faker/blob/next/src/locales/en_GB/location/county.ts |
Interesting, I assumed that the default locale included all possible locales. Could there be additional documentation explaining 1) the default locale's data and 2) how choosing a locale impacts the size of the dataset you'll generate from? |
It's English. Not specific to any country. So you might get both color or colour.
IMO this is a hard one because it litterally generates data for the thing you selected. So en is any English. en_US is American English + America specific things and uses the general English stuff where no specifc values exists. So instead of jugling with more precise and hard to maintain definitions I would rather try to fix issues such as these on a data level. |
@ST-DDT I'm mostly asking for clarity on @matthewmayer's comment:
I never tried this, but if it's true, why is it that when picking |
en_GB and en_US have a longer list of counties (real British counties and popular US county names) en only has 6 (a truncated list of British counties) this is a historical glitch which we havent got around to fixing yet. There's a lot of legacy data issues like this which are getting gradually cleaned up. |
After reading through this thread I'm still not sure how this would be solved. Should |
I think it should probably just be the same as en_US as the en states are US states. |
Pre-Checks
Describe the bug
Using the
county
method with theuniqueArray
completely crashes not just faker but my entire runtime. In my case, I discovered it in a React + Storybook project, where I switched from usingcountry
to usingcounty
, and my entire browser became unresponsive.Attached is a stackblitz (based on the one linked in the docs), that does the same thing, comparing the
country
method to thecounty
method using theuniqueArray
helper, where generating some unique countries works fine, but counties do not.Minimal reproduction code
https://stackblitz.com/edit/faker-js-demo-rqnnk9?file=index.ts
Additional Context
I personally use faker in a Vite + Storybook + React environment, using ES Modules targeting an ESNext build. However, it is reproduce-able (as shown in the stackblitz) in plain JS modules.
Environment Info
Which module system do you use?
Used Package Manager
pnpm
The text was updated successfully, but these errors were encountered: