-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat: improved errors when config can not be found #85
Conversation
src/configs.ts
Outdated
@@ -83,13 +140,19 @@ export async function resolveConfigPath(options: ResolveConfigPathOptions) { | |||
*/ | |||
export async function readConfig( | |||
options: ReadConfigOptions, | |||
): Promise<{ configs: FlatConfigItem[], payload: Payload, dependencies: string[] }> { | |||
): Promise<ConfigPathLegacyError | ConfigPathError | { configs: FlatConfigItem[], payload: Payload, dependencies: string[] }> { |
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.
Why don't we use throw instead?
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.
@antfu As throws are not typed in TypeScript and can be intertwined with other kinds of exceptions
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 think we could throw and use if (error instanceof ConfigPathLegacyError)
to do the type guard
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 could, but not sure it would make the code simpler :)
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 don't think it would make it more complicated either - but I think the point is that errors are supposed to be thrown, and loadConfig
by it's name should returns the config
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.
Sorry that I never got to fixing this 🙈
Speaking on this topic, ran into this standard proposal the other day: https://github.com/arthurfiorette/proposal-safe-assignment-operator
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.
No worries at all.
Yeah I saw it. Would love to see it landed someday!
Fixes #82
When encountering no flat config it now checks for a legacy config and if found it will output this error message now:
And if no legacy config file is found either, then it will tell the user what files it looked for and in what folder: