-
Notifications
You must be signed in to change notification settings - Fork 15
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
markdoliner-doma
wants to merge
2
commits into
creditkarma:master
Choose a base branch
from
StatesTitle:mdoliner-st/Add_a_StructLike_class_that_extends_Error
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add a StructLike class that extends Error. #132
markdoliner-doma
wants to merge
2
commits into
creditkarma:master
from
StatesTitle:mdoliner-st/Add_a_StructLike_class_that_extends_Error
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Types of changes
Checklist: