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

Convert "Invalid source root" errors to UserErrors #1282

Merged
merged 1 commit into from
Oct 6, 2022

Conversation

aeisenberg
Copy link
Contributor

This is an internal change. No changelog note required.

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.

@aeisenberg aeisenberg requested a review from a team as a code owner October 4, 2022 18:44
src/init.ts Outdated
// Handle the situation where init is called twice
// for the same database in the same job.
// Check if we need to re-throw the error as a UserError in order to avoid
// counting this error towards our internal error budget.
if (
Copy link
Contributor

Choose a reason for hiding this comment

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

Time to extract these conditions into their own shouldReportAsUserError helper function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

@aeisenberg aeisenberg changed the base branch from main to aeisenberg/cli-config-processing October 4, 2022 19:07
@aeisenberg aeisenberg force-pushed the aeisenberg/user-error-source-root branch from 7c40d0f to 7c11f80 Compare October 4, 2022 19:08
@aeisenberg
Copy link
Contributor Author

Rebasing in order to pick up a fix in integration tests from #1281.

Base automatically changed from aeisenberg/cli-config-processing to main October 4, 2022 19:30
adityasharad
adityasharad previously approved these changes Oct 4, 2022
Copy link
Contributor

@adityasharad adityasharad left a comment

Choose a reason for hiding this comment

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

Looks good, minor suggestions only.

src/init.ts Outdated
return new util.UserError(
`Is the "init" action called twice in the same job? ${e.message}`
);
} else if (
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need the else since you're returning early.

src/init.ts Outdated
e.message?.includes("Invalid source root")
) {
return new util.UserError(e.message);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar, this can just be a final fall-through return statement.

Copy link
Contributor

@angelapwen angelapwen left a comment

Choose a reason for hiding this comment

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

Just a question/suggestion, not approving yet because it'll probably be dismissed by another commit anyway.

* attributed to the user, otherwise the original error.
*/
function processError(e: any): Error {
if (!(e instanceof Error)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious: when would e not be an instanceof Error if it was sent from the try/catch block? Or is this just good practice in any error handling function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In javascript, you can "throw" anything. So you are not guaranteed that a catch clause is actually catching an Error instance. In practice, you should only throw errors. Typescript is just being pedantic here, and so is this code.

src/init.ts Outdated Show resolved Hide resolved
@aeisenberg aeisenberg force-pushed the aeisenberg/user-error-source-root branch from befd353 to 9e044c5 Compare October 6, 2022 16:28
@aeisenberg aeisenberg merged commit 84dffe7 into main Oct 6, 2022
@aeisenberg aeisenberg deleted the aeisenberg/user-error-source-root branch October 6, 2022 17:48
@github-actions github-actions bot mentioned this pull request Oct 6, 2022
7 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.

3 participants