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

Throw error for unknown check types #213

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

alexmuller
Copy link
Member

@alexmuller alexmuller commented Apr 14, 2023

This is probably a new major semver.

@andygout observed in Financial-Times/next-newsletter-signup#434 that when you pass in a check with type text the check just silently doesn't show up. That is apparently intentional (at least according to n-health) but I think it's silly behaviour. Thanks Andy!

This change makes n-health throw an error whenever it's told to run a check with a type that it doesn't understand.

This PR might be easier to review commit-by-commit to see the test for the previous behaviour. You can add ?w=1 to the GitHub diff URL to hide whitespace changes.

@alexmuller alexmuller requested review from a team as code owners April 14, 2023 15:34
Copy link
Contributor

@andygout andygout left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fab - thanks @alexmuller

@alexmuller alexmuller force-pushed the throw-error-for-unknown-check-types branch from 8ec4858 to 609f0d2 Compare April 30, 2024 11:03
Comment on lines +8 to +12
if (!(check.type in healthchecks)) {
throw new Error(
`Attempted to create check '${check.name}' of type ${check.type} which does not exist`
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: instead of throwing on the first undefined check, this could collect all the undefined checks and throw an error for all of them. would prevent a user playing error whackamole

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: this would crash the app at startup right? while we'd hope that would be caught by users in local dev, there's still a chance it could creep through to review/staging apps. maybe a safer alternative would be to output a permanently-failing check for undefined checks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants