-
-
Notifications
You must be signed in to change notification settings - Fork 919
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
Introduce a way to get details about missing locale data when using them #893
Comments
Just to prioritize some issues, I would see should be handled before this issue |
We might also need a way to mark/handle explicitly missing data. |
Team decision If faker.definitions.category.entry is not defined we will throw an error. |
What blocks us from "simply" making all definitions required? If we currently don't have any they could be filled with an empty array. Then the next step would be to throw an error in Is that the desired behavior or did I misunderstood the issue? |
The current behavior is to fallback to the fallback locale ie English en which is defined for nearly everything. In which cases would we want to explicitly throw an error? |
Yes, that is correct. But this happens when accessing the actual locale data via the Lines 191 to 196 in f9e5ba7
Which could simply be replaced by checking against the
I'm talking about two different things here (locale data accessing and |
Currently only:
But we have a PR that adds more:
There are three problems with that.
This issue is explictly about improving the DX by exposing which data are missing: new FakerError("This faker instance does not have any data for ``location.postcode_by_state``. Please make sure you configured the correct fallbacks or create a PR that adds these data to Faker for your locale."); instead of: new FakerError("Cannot invoke helpers.arrayElement() with an empty array") |
In the case where you don't want the English fallback and you explicitly want only data in your selected locale. |
Which IMO is likely to change in implementation, but will still be some kind of Proxy (to throw useful error messages).
See #893 (comment) (1. argument)
Which is a different issue altogether: #219 |
Ok so this this mostly a internal issue For most consumers of the library nothing much changes unless you are explicitly not falling back to en (which requires a non-default setup) or using one of the rare methods which don't have a en fallback? |
Note to self: Do it. |
I have to create a PR for moving |
Blocked by #1978. |
I've been thinking about this, and perhaps this could be an explicit option on the Faker instance, because in some cases you might want an error, and in some cases e.g. if you are directly using calls to Faker in templates, you would rather just have undefined returned. Suppose you have a method which is only defined in certain locales (say Then you could do
|
Team Decision
While this is an interesting feature, it is not possible to implement this in a type safe way. If we add There might be ways to handle that using some kind of Faker type overwrite. |
That's why JavaScript is better than typescript 😂😂😂 |
Team Decision We want this for v8.0. |
Clear and concise description of the problem
Currently many methods look like this:
However, the current locale does not have a value for it, then it will return
'a' | 'b' | 'c'
.It would be nice, if the method would throw an error, with details about missing data.
It should still be possible to check whether the data exists without throwing and catching an error.
This kind of blocks the removal of the default from
random.arrayElement()
Suggested solution
Change the
faker.definitions
to throw an error, if the data are absent.Introduce
faker.extensions
that would return undefined (the currentfaker.definitions
behavior).(Not sure about the name)
Alternative
Check the data before using it each time. This reduces the code readability a lot.
Additional context
IMO
faker.definitions
should change its behavior, instead of adding a new field for it, because I assume, the default expectation is that the data are present. Most of our methods wouldn't change either. Only some of them would, where the data are explicitly optional.The text was updated successfully, but these errors were encountered: