-
-
Notifications
You must be signed in to change notification settings - Fork 943
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
refactor(location)!: throw error if state is unknown #1760
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have trouble running the tests locally, you can use CI=true pnpm run test watch
.
src/modules/location/index.ts
Outdated
@@ -64,9 +64,9 @@ export class LocationModule { | |||
const zipRange = this.faker.definitions.location.postcode_by_state?.[state]; | |||
if (zipRange) { | |||
return String(this.faker.number.int(zipRange)); | |||
} else { | |||
throw new Error(`${state} is invalid.`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please throw a FakerError instead.
Maybe also add a list with allowed keys and a hint where these keys are comming from.
E.g. faker.definitions.location.postcode_by_state only contains data for [...]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you might want to have different errors for the
- where the locale doesn't support postcode_by_state at all (e.g. en, de)
- where the locale does support postcode_by_state, but this is an unknown state (say XX in en_US).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will handle the first part centrally: #893 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm i think this is a weird edge case though where the fallback locale (en) doesn't contain the data, which is unusual.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ST-DDT Thanks for the review 🙏
I'll use FakeError
instead + attach available keys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have fixed the code to throw FakerError and updated the docstring, but I'm not sure how to make the tests pass. It looks like en
locale is used as default in seededTests
, and zipCodeByState
will always throw with en
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This documentation needs to be updated to reflect that an error would now be thrown. Also I think it could be make clearer this doesn't work in the default en
locale, but only in en_US
.
The unresolved conflict brings an issue: the
Once we said we only want to have method calls (outside the helpers module) that can always be called without passing any arguments. In this case state is always required otherwise it would always throw an error. We will discuss this in an upcoming meeting. |
Team Decision
Thanks for your contribution anyway! |
Fixes #1736