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

feat!: Refactor error handling #159

Merged
merged 37 commits into from
Aug 1, 2024
Merged

feat!: Refactor error handling #159

merged 37 commits into from
Aug 1, 2024

Conversation

joe-yeager
Copy link
Contributor

@joe-yeager joe-yeager commented Jul 18, 2024

Description and Context

Note: This will be a breaking change, so this PR is targeting the next branch and will be in the next major

Whats changed:

Removals

  • Removed all thrower methods because they were thin wrappers obscure our intent by adding an additional layer in front of the throw. Explicitly throwing the error makes our intentions clearer, and actually makes our code easier to statically analyze. The change uncovered 2 cases where we are calling throwX in a try block, which then obscures the intended error message with a new more generic error message. Methods removed:
    • throwError
    • throwErrorWithMessage
    • throwApiError
    • throwApiUploadError
    • throwValidationError
    • throwAuthErrorWithMessage
    • throwFileSystemError
  • Removes HubSpotAuthError, because we now have HubSpotHttpError and we can check if it is an auth error using isAuthError in the errors module
  • parseValidationErrors is no longer exported
  • getHubSpotHttpErrorWithContext is no longer exported

Additions

  • Creates a new Error object FileSystemError to replace the need for throwFileSystemError

Changes

  • Compresses apiErrors, standardErrors, and fileSystemErrors into a single errors module.
  • Moves all of the logic for extraction of error messages from http responses into the HubSpotHttpError class and makes it an automatic operation.
    • This means the HubSpotHttpError with have the user friendly http error message in it's message property automatically.
    • The extraction of the context object is automatic on instantiation of the HubSpotHttpError, but can be overridden

Screenshots

TODO

Who to Notify

@brandenrodgers @camden11 @kemmerle

@joe-yeager joe-yeager changed the base branch from jy/POC-Wrap-Axios-Errors to next July 25, 2024 16:23
@joe-yeager joe-yeager changed the title Jy/simplify error handling feat!: Refactor error handling Jul 25, 2024
lib/fs.ts Outdated Show resolved Hide resolved
@joe-yeager joe-yeager marked this pull request as ready for review July 25, 2024 20:18
throwError(e);
}
}
const response = await fetchAccessToken(personalAccessKey, env, accountId);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a great example of the value of this 🎉

this.context = { ...generatedContext, ...context };
}

private parseValidationErrors(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we might need to dig into this parse validation util. I noticed that we're logging out some of the important context, but not all of it. For example:

Here's what logs out when I get a "missing scopes" error response. I can get this by trying to run this command against my developer portal, which doesn't have the right content scopes to access CMS data.
image

It's trying to tell me the scopes I'm missing, but it's not including all of the information that I need. This is the shape of responseData when that happens:
image

context here contains the scopes, like this: ["content", "content"] (not sure why it's in there twice)


Also, from what I can tell, in the previous version of the error handling we only called it in a few places (throwApiUploadError is the only util that called isApiUploadValidationError, which ran this validation parsing logic). I wonder if it will have an impact on some of the existing error messages?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a method to log the formattedValidationErrors that the CLI now calls if the error is a validation error.

I'll look into using the context object. How did you trigger missing scopes error? Just remove those scopes from the app?

Copy link
Contributor

Choose a reason for hiding this comment

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

The reference to "app" here is misleading. In reality the error is referencing the personal access key. So you can generate a personal access key that doesn't have any scopes, and then try to run various CLI commands.

Copy link
Contributor

@camden11 camden11 left a comment

Choose a reason for hiding this comment

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

This is looking great, really cleans things up nicely and should hopefully make the experience of using and contributing to local-dev-lib a lot better. I haven't tested yet, but I did my best to look over everything and didn't notice any problems. Are there any particular areas you need help with extra testing or that I should give a more focused look?

models/HubSpotHttpError.ts Show resolved Hide resolved
@joe-yeager
Copy link
Contributor Author

joe-yeager commented Jul 29, 2024

Are there any particular areas you need help with extra testing or that I should give a more focused look?

@camden11 Since it is such a wide spreading change, I think we really need to try to touch as many places as possible, so just widespread general testing.

Copy link
Contributor

@camden11 camden11 left a comment

Choose a reason for hiding this comment

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

I still haven't had a chance to test this much, but assuming there will be plenty of time to text the next branch if its not going to be merged for a bit.

Looked everything over again and LGTM

Copy link
Contributor

@brandenrodgers brandenrodgers left a comment

Choose a reason for hiding this comment

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

This lgtm! I did some testing locally and it all seems to be WAD. We'll have to hammer on it some more since it has a wide impact, but this is good to go into the next branch 👌

@joe-yeager joe-yeager merged commit 2f1b8e0 into next Aug 1, 2024
@joe-yeager joe-yeager deleted the jy/simplify-error-handling branch August 1, 2024 16:02
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