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

Safely access caught Error properties #3196

Merged
merged 2 commits into from Sep 8, 2021

Conversation

abdvl
Copy link
Contributor

@abdvl abdvl commented Sep 3, 2021

Update in a few places to safely access caught Error properties via typescript4 unknown on catch Clause Bindings https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#unknown-on-catch-clause-bindings

Checklist

  • The PR conforms to DataHub's Contributing Guideline (particularly Commit Message Format)
  • Links to related issues (if applicable)
  • Tests for the changes have been added/updated (if applicable)
  • Docs related to the changes have been added/updated (if applicable)

Update in a few places to safely access caught Error properties via typescript4 `unknown on catch Clause Bindings`  https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#unknown-on-catch-clause-bindings
@@ -101,9 +101,9 @@ export default function DescriptionField({
await onUpdate(desc || '');
// message.destroy();
// message.success({ content: 'Updated!', duration: 2 });
} catch (e) {
} catch (e: unknown) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are there cases where "e" is not an Error? I have not encountered them but interested to hear if you've seen this!

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 think this is the original proposal. It tries to be more specific on the error types, like other languages. Like the example from that thread

try {
  externalApi()
} catch(e) {
  if (e instanceof Error) {
    // Probably send this error to developer of API
  } else if (e instanceof ApiError) {
    // We messed up, log it and fix it in next patch
  }
}

Copy link
Contributor

@shirshanka shirshanka left a comment

Choose a reason for hiding this comment

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

LGTM!

@shirshanka shirshanka merged commit 8dbbec4 into datahub-project:master Sep 8, 2021
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