Skip to content
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

Merged
merged 9 commits into from
Jul 31, 2023
Merged

Improve config error handling #7852

merged 9 commits into from
Jul 31, 2023

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Jul 28, 2023

Changes

  • Improve error handling on initial startup and dev restarts
  • Handle error logging directly in the places where the error emits
  • Simplify dev() public JS API (remove beforeRestart and handleConfigError)

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.

@changeset-bot
Copy link

changeset-bot bot commented Jul 28, 2023

⚠️ No Changeset found

Latest commit: 4060c07

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jul 28, 2023
Copy link
Member Author

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.

Comment on lines +88 to +92
try {
result = await AstroConfigRelativeSchema.parseAsync(userConfig);
} catch (e) {
// Improve config zod error messages
if (e instanceof ZodError) {
Copy link
Member Author

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.

Comment on lines -40 to -41
// eslint-disable-next-line no-console
beforeRestart: () => console.clear(),
Copy link
Member Author

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.

Copy link
Member

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

Comment on lines +19 to +22
experimental: {
assets: typeof flags.experimentalAssets === 'boolean' ? flags.experimentalAssets : undefined,
},
};
Copy link
Member

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?

Copy link
Member

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.

Comment on lines +19 to +22
experimental: {
assets: typeof flags.experimentalAssets === 'boolean' ? flags.experimentalAssets : undefined,
},
};
Copy link
Member

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.

packages/astro/src/core/errors/errors.ts Outdated Show resolved Hide resolved
packages/astro/src/core/dev/restart.ts Outdated Show resolved Hide resolved
Comment on lines -40 to -41
// eslint-disable-next-line no-console
beforeRestart: () => console.clear(),
Copy link
Member

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
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

@bluwy bluwy merged commit 5d3d807 into js-api Jul 31, 2023
@bluwy bluwy deleted the refactor-config-error-handling branch July 31, 2023 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants