-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Marshal and unmarshal @ocap/errors
#154
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
Conversation
07f97ca to
3c7db2d
Compare
7f0cadf to
b622374
Compare
b622374 to
77d6ca6
Compare
rekmarks
left a comment
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.
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.
e8d9eeb to
b587495
Compare
ff208cf to
93c4084
Compare
93c4084 to
4a455f3
Compare
rekmarks
left a comment
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.
Just a couple more things.
packages/errors/src/constants.ts
Outdated
| /** | ||
| * 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment in isMarshaledOcapError.ts.
| /** | |
| * 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)])), | |
| }; | |
| const marshaledErrorSchema = { | |
| [ErrorSentinel]: literal(true), | |
| message: string(), | |
| data: optional(JsonStruct), | |
| stack: optional(string()), | |
| }; | |
| /** | |
| * Struct to validate marshaled errors. | |
| */ | |
| export const MarshaledErrorStruct = object({ | |
| ...marshaledErrorSchema, | |
| cause: optional(union([string(), lazy(() => MarshaledErrorStruct)])), | |
| }) as Struct<MarshaledError>; | |
| /** | |
| * Struct to validate marshaled ocap errors. | |
| */ | |
| export const MarshaledOcapErrorStruct = object({ | |
| ...marshaledErrorSchema, | |
| code: ErrorCodeStruct, | |
| data: JsonStruct, | |
| cause: optional(union([string(), lazy(() => MarshaledOcapErrorStruct)])), | |
| }) as Struct<MarshaledOcapError>; | |
| /** | |
| * 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)])), | |
| }; |
rekmarks
left a comment
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!
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.