feat(ses): add support for "code" prop in SES-managed Errors#3130
feat(ses): add support for "code" prop in SES-managed Errors#3130
Conversation
|
|
What I'd really like to see here is a endo/packages/ses/src/error/assert.js Lines 341 to 352 in e6d46c7 The workaround is to just wrap |
e6d46c7 to
0b2ff5a
Compare
packages/ses/types.d.ts
Outdated
| /** | ||
| * An `Error` with a `code` property. | ||
| */ | ||
| export type SesError = Error & { code?: string }; |
There was a problem hiding this comment.
Open to naming suggestions
There was a problem hiding this comment.
(We could have used module augmentation to extend the global Error interface with a code?: string prop, but that would affect all downstream consumers of ses, which would be inconsiderate)
There was a problem hiding this comment.
Under any name, I don't like introducing a new type for this purpose if possible.
What about cause and errors? Do they have this problem too? If not, can we treat code the same way? Once we support SuppressedError (hopefully soon) we will also need to support the further instance properties error and suppressed.
kriskowal
left a comment
There was a problem hiding this comment.
Needs changeset and consensus on names.
packages/ses/types.d.ts
Outdated
| /** | ||
| * An `Error` with a `code` property. | ||
| */ | ||
| export type SesError = Error & { code?: string }; |
There was a problem hiding this comment.
Consider CodedError (imprecise) or OptionallyCodedError (ew) or MaybeCodedError (ew but less so) or ErrorConCodé (facetious) or CodableError (getting there, leaves air for CodedError to require the code) since this isn’t particularly intrinsic to SES.
type CodedError = Error & { code: string };
type CodableError = Error & {code?: string };Could be that we overload these functions so that CodedError is implied by presence of code option.
There was a problem hiding this comment.
"Codeträger?" "Fehlercodetragendesding?" "Codebesitzend" really rolls off the tongue
There was a problem hiding this comment.
Going w/ CodableError. 🐟
- Adds a new `string` option to `AssertMakeErrorOptions`, `code`
- If a `string`, will be an non-enumerable property of the `Error` instance returned by `makeError`.
- To avoid mutating global types, a new type `SesError` is introduced which is simply `Error & {code?: string}`.
Note that `code` is expected to be a `string` here, but only by convention; the language will not enforce this (as per the below proposal).
Ref: https://github.com/tc39-transfer/proposal-error-code-property
has nothing to do with fish
c58a919 to
bf477a0
Compare
| * such as `stack` on v8 (Chrome, Brave, Edge?) | ||
| * - `sanitizeError` will freeze the error, preventing any correct engine from | ||
| * adding or | ||
| * altering any of the error's own properties `sanitizeError` is done. |
There was a problem hiding this comment.
| * altering any of the error's own properties once `sanitizeError` is done. |
This was my mistake, but might as well add as a drive-by to this PR is you don't mind.
| }); | ||
| } | ||
| } | ||
| if (code !== undefined && typeof code === 'string') { |
There was a problem hiding this comment.
Here, there's no good answer for "what do to if code is not a string?". Rather, I think that here, following the proposal, you should not filter by the value of code. Rather, put this value test above in sanitizeError. There, if you see a non-string code, delete it and add it to droppedDetails so that it is hidden but shows up as a diagnostic on console output.
packages/ses/types.d.ts
Outdated
| /** | ||
| * An `Error` with a `code` property. | ||
| */ | ||
| export type SesError = Error & { code?: string }; |
There was a problem hiding this comment.
Under any name, I don't like introducing a new type for this purpose if possible.
What about cause and errors? Do they have this problem too? If not, can we treat code the same way? Once we support SuppressedError (hopefully soon) we will also need to support the further instance properties error and suppressed.
|
See also DRAFT PRs #2223 and #2429 . Like them, we need to coordinate this change with @endo/pass-style and @endo/marshal so that |
stringoption toAssertMakeErrorOptions,codestring, will be an non-enumerable property of theErrorinstance returned bymakeError.SesErroris introduced which is simplyError & {code?: string}.Note that
codeis expected to be astringhere, but only by convention; the language will not enforce this (as per the below proposal).Ref: https://github.com/tc39-transfer/proposal-error-code-property