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

Add a StructLike class that extends Error. #132

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

markdoliner-doma
Copy link

@markdoliner-doma markdoliner-doma commented Jun 1, 2020

Description

Exception classes should extend this so that they derive from Error.

Motivation and Context

As mentioned in the thrift-typescript GitHub issue, it's useful for exceptions to derive from Error so they have stack traces and because some frameworks expect it. The GitHub issue mentions graphql-js. Jest's toThrow() function would also benefit from this. See the related thrift-typescript PR for more details.

How Has This Been Tested?

Tested locally.

Possible remaining work:

  • Add a test?
  • Bump version number so end users can require the new version.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Exception classes should extend this so that they derive from Error.

As mentioned in [the thrift-typescript GitHub issue](creditkarma/thrift-typescript#178), it's useful for exceptions to derive from Error so they have stack traces and because some frameworks expect it. The GitHub issue mentions graphql-js. Jest's `toThrow()` function would also benefit from this. See the related thrift-typescript PR for more details.

Possible remaining work:
- Add a test?
- Bump version number so end users can require the new version.
@markdoliner-doma
Copy link
Author

I can clean this up a little (fix tests, update documentation as needed, read the CONTRIBUTING document), but wanted to get feedback from Credit Karma folks to make sure I'm heading in the right direction before spending more time on it.

markdoliner-doma added a commit to StatesTitle/thrift-server that referenced this pull request Aug 28, 2020
I'm merging this change into the all_states_title_changes branch. For the full PR description see [the PR for merging this change into Credit Karma's master branch](creditkarma#132).
markdoliner-doma added a commit to StatesTitle/thrift-server that referenced this pull request Sep 1, 2020
…lass_that_extends_Error

I'm merging this change into the all_states_title_changes branch. For the full PR description see [the PR for merging this change into Credit Karma's master branch](creditkarma#132).
When using the new version of thrift-typescript where exceptions derive from `Error`, it's problematic to shadow `Error`'s `message` field. In this case the problem is that our message was optional and `Error`'s message is required, but I think it's good practice to avoid reusing `message` altogether.

Before this change the `prettier --write 'src/**/*.ts'` command was showing this error:
```
src/tests/generated/common/AuthException.ts:81:12 - error TS2416: Property 'message' in type 'AuthException' is not assignable to the same property in base type 'ErrorStructLike'.
  Type 'string | undefined' is not assignable to type 'string'.
    Type 'undefined' is not assignable to type 'string'.

81     public message?: string;
              ~~~~~~~

src/tests/generated/exceptions/InvalidResult.ts:81:12 - error TS2416: Property 'message' in type 'InvalidResult' is not assignable to the same property in base type 'ErrorStructLike'.
  Type 'string | undefined' is not assignable to type 'string'.
    Type 'undefined' is not assignable to type 'string'.

81     public message?: string;
              ~~~~~~~

Found 4 errors.
```
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.

1 participant