-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Improve config error handling #7852
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.
This file is a rename from load-settings.ts
but Git doesn't see it that way.
try { | ||
result = await AstroConfigRelativeSchema.parseAsync(userConfig); | ||
} catch (e) { | ||
// Improve config zod error messages | ||
if (e instanceof ZodError) { |
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.
Errors are now logged more directly.
// eslint-disable-next-line no-console | ||
beforeRestart: () => console.clear(), |
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.
The beforeRestart
was only created because on console.clear()
, as we don't want to call console.clear
in tests (test results gets removed).
Personally I find clearing the console moves and cuts out the terminal a lot that it's better to not do it instead, so I removed it.
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.
Totally agree, especially if there are scripts/users that rely on stdout/stderr
experimental: { | ||
assets: typeof flags.experimentalAssets === 'boolean' ? flags.experimentalAssets : undefined, | ||
}, | ||
}; |
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.
do we have a --experimentalViewTransitions
flag?
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 don't; I believe we forgot about it. We should probably add it.
experimental: { | ||
assets: typeof flags.experimentalAssets === 'boolean' ? flags.experimentalAssets : undefined, | ||
}, | ||
}; |
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 don't; I believe we forgot about it. We should probably add it.
// eslint-disable-next-line no-console | ||
beforeRestart: () => console.clear(), |
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.
Totally agree, especially if there are scripts/users that rely on stdout/stderr
}); | ||
} catch (e) { | ||
const configPathText = configFile ? colors.bold(configFile) : 'your Astro config'; | ||
// Config errors should bypass log level as it breaks startup |
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.
About the comment: Is it because --silent
can potentially not log these errors?
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.
Yeah --silent
would otherwise not log that the config failed to load. Try to pass the logging
down here is a bit tricky, especially the fact that an Astro config logLevel
can also contribute to how logging
works.
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.
Actually there's no logLevel
config in the Astro config, got it mixed up. I think it's still probably fine always logging it here as the other code in this file also does that, but I'll revisit this again if it's not ideal.
Changes
dev()
public JS API (removebeforeRestart
andhandleConfigError
)Testing
Existing tests should pass. We don't have a lot of these kind of tests, I also tested the commands manually.
Docs
n/a. internal change, the error messages should still appear unchanged.