Uh oh!
There was an error while loading. Please reload this page.
feat: Marshal and unmarshal @ocap/errors - #154
Conversation
07f97ca to
3c7db2dCompare7f0cadf to
b622374Compareb622374 to
77d6ca6Compare
rekmarks
left a comment
There was a problem hiding this comment.
Nice! I have various questions and suggestions. For all of the errors, I left a number of suggestions on VatNotFoundError that are generally applicable.
Two big changes are harden:ing the error prototypes, error instances, and marshaled errors. You may want to do that after any changes I propose about e.g. reorganizing the types / utils.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
e8d9eeb to
b587495Compareff208cf to
93c4084Compare93c4084 to
4a455f3Compare| /** | ||
| * Struct to validate marshaled errors. | ||
| */ | ||
| export const MarshaledErrorStruct = object({ | ||
| [ErrorSentinel]: literal(true), | ||
| message: string(), | ||
| code: optional(ErrorCodeStruct), | ||
| data: optional(JsonStruct), | ||
| stack: optional(string()), | ||
| cause: optional(union([string(), lazy(() => MarshaledErrorStruct)])), | ||
| }) as Struct<MarshaledError>; | ||
| /** | ||
| * Base schema for validating Ocap error classes during error marshaling. | ||
| */ | ||
| export const baseErrorStructSchema = { | ||
| [ErrorSentinel]: literal(true), | ||
| message: string(), | ||
| code: ErrorCodeStruct, | ||
| data: JsonStruct, | ||
| stack: optional(string()), | ||
| cause: optional(union([string(), lazy(() => MarshaledErrorStruct)])), | ||
| }; |
There was a problem hiding this comment.
See comment in isMarshaledOcapError.ts.
| /** | |
| *Structtovalidatemarshalederrors. | |
| */ | |
| exportconstMarshaledErrorStruct=object({ | |
| [ErrorSentinel]: literal(true), | |
| message: string(), | |
| code: optional(ErrorCodeStruct), | |
| data: optional(JsonStruct), | |
| stack: optional(string()), | |
| cause: optional(union([string(),lazy(()=>MarshaledErrorStruct)])), | |
| })asStruct<MarshaledError>; | |
| /** | |
| *BaseschemaforvalidatingOcaperrorclassesduringerrormarshaling. | |
| */ | |
| exportconstbaseErrorStructSchema={ | |
| [ErrorSentinel]: literal(true), | |
| message: string(), | |
| code: ErrorCodeStruct, | |
| data: JsonStruct, | |
| stack: optional(string()), | |
| cause: optional(union([string(),lazy(()=>MarshaledErrorStruct)])), | |
| }; | |
| constmarshaledErrorSchema={ | |
| [ErrorSentinel]: literal(true), | |
| message: string(), | |
| data: optional(JsonStruct), | |
| stack: optional(string()), | |
| }; | |
| /** | |
| *Structtovalidatemarshalederrors. | |
| */ | |
| exportconstMarshaledErrorStruct=object({ | |
| ...marshaledErrorSchema, | |
| cause: optional(union([string(),lazy(()=>MarshaledErrorStruct)])), | |
| })asStruct<MarshaledError>; | |
| /** | |
| *Structtovalidatemarshaledocaperrors. | |
| */ | |
| exportconstMarshaledOcapErrorStruct=object({ | |
| ...marshaledErrorSchema, | |
| code: ErrorCodeStruct, | |
| data: JsonStruct, | |
| cause: optional(union([string(),lazy(()=>MarshaledOcapErrorStruct)])), | |
| })asStruct<MarshaledOcapError>; | |
| /** | |
| *BaseschemaforvalidatingOcaperrorclassesduringerrormarshaling. | |
| */ | |
| exportconstbaseErrorStructSchema={ | |
| [ErrorSentinel]: literal(true), | |
| message: string(), | |
| code: ErrorCodeStruct, | |
| data: JsonStruct, | |
| stack: optional(string()), | |
| cause: optional(union([string(),lazy(()=>MarshaledErrorStruct)])), | |
| }; |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
closes#150
Following #149, this PR modifies the marshaling functions in
@ocap/streamssuch that errors from@ocap/errorsare unmarshaled into their respective classes, based on the error code. It also extends thestringifyutility to support ocap errors.