-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
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
datahub-web-react/src/app/entity/shared/tabs/Documentation/components/LinkList.tsx
Outdated
Show resolved
Hide resolved
@@ -101,9 +101,9 @@ export default function DescriptionField({ | |||
await onUpdate(desc || ''); | |||
// message.destroy(); | |||
// message.success({ content: 'Updated!', duration: 2 }); | |||
} catch (e) { | |||
} catch (e: unknown) { |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
}
}
datahub-web-react/src/app/entity/shared/tabs/Documentation/components/LinkList.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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-bindingsChecklist