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

Refactor configuration errors #2105

Merged
merged 17 commits into from
Feb 8, 2024

Conversation

angelapwen
Copy link
Contributor

@angelapwen angelapwen commented Jan 30, 2024

As we add more configuration errors to improve our uptime measurements, I thought it would be nice to refactor the existing errors into their own file. I took inspiration from the FeatureConfig Record that we use for feature flags.

Also, I thought it would be nice to consolidate the place we check for configuration errors into codeql.ts, where the actual command invocations happen.

The PR also renames the UserError type to ConfigurationError to standardize on a single term.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm the readme has been updated if necessary.
  • Confirm the changelog has been updated if necessary.

@angelapwen angelapwen marked this pull request as ready for review January 30, 2024 14:25
@angelapwen angelapwen requested a review from a team as a code owner January 30, 2024 14:25
@angelapwen angelapwen changed the title Refactor config errors Refactor configuration errors Jan 30, 2024
Copy link
Contributor

@nickfyson nickfyson left a comment

Choose a reason for hiding this comment

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

I really like the direction, I think it makes a lot of sense to consolidate this class of errors and their handling into a single place. I've added a couple of comments/questions...

src/cli-config-errors.ts Outdated Show resolved Hide resolved
src/codeql.ts Outdated Show resolved Hide resolved
src/codeql.ts Outdated Show resolved Hide resolved
src/cli-config-errors.ts Outdated Show resolved Hide resolved
src/cli-config-errors.ts Outdated Show resolved Hide resolved
src/cli-config-errors.ts Outdated Show resolved Hide resolved
src/cli-config-errors.ts Outdated Show resolved Hide resolved
src/cli-config-errors.ts Outdated Show resolved Hide resolved
As we add more configuration errors, we can standardize throwing and catching them in the `codeql` file where we actually invoke the commands.

Also, rename to `isCliConfigurationError` for more clarity.
To maintain parity with the previous logic: only 1 of the 2 conditions needs to hold: either the exit codes match, or the error messages match.
And all associated methods/comments that say `user error`
Now that we are always appending the original error, this test needs to be updated.
@angelapwen
Copy link
Contributor Author

Okay.. the refactoring based off of the feedback took a bit longer/was more complex than expected, but I think I'm happy with the results 😸

  • Now, we simply call wrapCliConfigurationError on any errors thrown from CLI command invocations in codeql.ts. This will return the appropriate Error type (possibly a ConfigurationError, if it matches any of our known CliConfigErrorCategory values, and possibly with an additional error message prepended for additional context to the user).
  • There was a dependency cycle so I moved CommandInvocationError to the same file as the CLI configuration errors and renamed the file cli-errors.ts to cover both.
  • We're unconditionally appending the original error to the additional error message now, because I didn't think it was worth adding an extra case where we don't include the original CLI error. I updated the test cases in codeql.test.ts to accommodate.

Copy link
Contributor

@nickfyson nickfyson left a comment

Choose a reason for hiding this comment

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

I like the direction, couple of small queries!

src/status-report.ts Outdated Show resolved Hide resolved
src/codeql.ts Show resolved Hide resolved
src/codeql.ts Show resolved Hide resolved
nickfyson
nickfyson previously approved these changes Feb 8, 2024
Copy link
Contributor

@nickfyson nickfyson left a comment

Choose a reason for hiding this comment

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

🚀

nickfyson
nickfyson previously approved these changes Feb 8, 2024
Copy link
Contributor

@nickfyson nickfyson left a comment

Choose a reason for hiding this comment

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

🚀

@angelapwen angelapwen enabled auto-merge (squash) February 8, 2024 17:08
@angelapwen angelapwen merged commit 1515e2b into github:main Feb 8, 2024
303 checks passed
@angelapwen angelapwen deleted the refactor-config-errors branch February 8, 2024 17:22
@github-actions github-actions bot mentioned this pull request Feb 13, 2024
8 tasks
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