Skip to content

feat: Custom Error Classes with Error Codes - #149

Merged
sirtimid merged 11 commits into
mainfrom
sirtimid/custom-error-classes
Oct 15, 2024
Merged

feat: Custom Error Classes with Error Codes#149
sirtimid merged 11 commits into
mainfrom
sirtimid/custom-error-classes

Conversation

@sirtimid

Copy link
Copy Markdown
Member

closes#95

This PR adds custom error classes with unique error codes. It establishes the base error class, and use that to createerrors in kernel package classes Vat, Kernel and Supervisor.

@sirtimid
sirtimid requested a review from a team as a code ownerOctober 11, 2024 13:46
@socket-security

socket-securityBot commented Oct 11, 2024

Copy link
Copy Markdown

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

PackageNew capabilitiesTransitivesSizePublisher
npm/@es-joy/jsdoccomment@0.49.0None0121 kBbrettz9
npm/@lavamoat/allow-scripts@3.3.0Transitive: environment, filesystem+2161 kB
npm/@rollup/rollup-android-arm-eabi@4.24.0None01.46 MBguybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-android-arm64@4.24.0None02.06 MBguybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-darwin-arm64@4.24.0None02.18 MBguybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-darwin-x64@4.24.0None02.33 MBguybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-arm-gnueabihf@4.24.0None02.22 MBguybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-arm-musleabihf@4.24.0None02.22 MBguybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-arm64-gnu@4.24.0None02.2 MBguybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-arm64-musl@4.24.0None02.12 MBguybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-powerpc64le-gnu@4.24.0None02.76 MBguybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-riscv64-gnu@4.24.0None02.25 MBguybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-s390x-gnu@4.24.0None03.84 MBguybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-x64-gnu@4.24.0None02.46 MBguybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-x64-musl@4.24.0None02.46 MBguybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-win32-arm64-msvc@4.24.0None02.76 MBguybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-win32-ia32-msvc@4.24.0None02.53 MBguybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-win32-x64-msvc@4.24.0None03.28 MBguybedford, lukastaegert, rich_harris, ...1 more
npm/@types/node@18.19.55None02.02 MBtypes
npm/@vitest/coverage-v8@2.1.3None0114 kBvitestbot
npm/@vitest/expect@2.1.3None0150 kBantfu, oreanno, patak, ...1 more
npm/@vitest/mocker@2.1.3None+1139 kBvitestbot
npm/@vitest/pretty-format@2.1.3environment045.5 kBvitestbot
npm/@vitest/runner@2.1.3None088.9 kBantfu, oreanno, patak, ...1 more
npm/@vitest/snapshot@2.1.3None085.2 kBantfu, oreanno, patak, ...1 more
npm/@vitest/spy@2.1.3None019.1 kBantfu, oreanno, patak, ...1 more
npm/@vitest/utils@2.1.3None0155 kBantfu, oreanno, patak, ...1 more
npm/@vue/compiler-core@3.5.12None0618 kBsoda, yyx990803
npm/@vue/compiler-dom@3.5.12None0640 kBsoda, yyx990803
npm/@vue/compiler-sfc@3.5.12None02.48 MBsoda, yyx990803
npm/@vue/compiler-ssr@3.5.12None047.3 kBsoda, yyx990803
npm/@vue/shared@3.5.12None086.5 kBsoda, yyx990803
npm/eslint-plugin-jsdoc@50.4.0filesystem+22.1 MBgajus
npm/get-east-asian-width@1.3.0None015.7 kBsindresorhus
npm/listr2@8.2.5None+2305 kBcenk1cenk2
npm/magic-string@0.30.12None0464 kBantfu
npm/package-json-from-dist@1.0.1None036.5 kBisaacs
npm/rollup@4.24.0None02.59 MBeventualbuddha, lukastaegert, rich_harris, ...2 more
npm/tsconfck@3.1.4None069.5 kBdominik_g
npm/typedoc@0.26.9None+12.45 MBtypedoc-bot
npm/vite-node@2.1.3None0204 kBantfu, oreanno, patak, ...1 more
npm/vite@5.4.9None03.26 MBantfu, patak, soda, ...2 more
npm/vitest@2.1.3environment, eval01.68 MBvitestbot

🚮 Removed packages:npm/@babel/code-frame@7.24.7, npm/@babel/generator@7.25.6, npm/@babel/helper-string-parser@7.24.8, npm/@babel/helper-validator-identifier@7.24.7, npm/@babel/highlight@7.24.7, npm/@babel/parser@7.25.6, npm/@babel/template@7.25.0, npm/@babel/traverse@7.25.6, npm/@es-joy/jsdoccomment@0.48.0, npm/@lavamoat/allow-scripts@3.2.1, npm/@rollup/rollup-android-arm-eabi@4.22.4, npm/@rollup/rollup-android-arm64@4.22.4, npm/@rollup/rollup-darwin-arm64@4.22.4, npm/@rollup/rollup-darwin-x64@4.22.4, npm/@rollup/rollup-linux-arm-gnueabihf@4.22.4, npm/@rollup/rollup-linux-arm-musleabihf@4.22.4, npm/@rollup/rollup-linux-arm64-gnu@4.22.4, npm/@rollup/rollup-linux-arm64-musl@4.22.4, npm/@rollup/rollup-linux-powerpc64le-gnu@4.22.4, npm/@rollup/rollup-linux-riscv64-gnu@4.22.4, npm/@rollup/rollup-linux-s390x-gnu@4.22.4, npm/@rollup/rollup-linux-x64-gnu@4.22.4, npm/@rollup/rollup-linux-x64-musl@4.22.4, npm/@rollup/rollup-win32-arm64-msvc@4.22.4, npm/@rollup/rollup-win32-ia32-msvc@4.22.4, npm/@rollup/rollup-win32-x64-msvc@4.22.4, npm/@types/node@18.19.51, npm/@vitest/coverage-v8@2.1.2, npm/@vitest/expect@2.1.2, npm/@vitest/mocker@2.1.2, npm/@vitest/pretty-format@2.1.2, npm/@vitest/runner@2.1.2, npm/@vitest/snapshot@2.1.2, npm/@vitest/utils@2.1.2, npm/@vue/compiler-core@3.5.8, npm/@vue/compiler-dom@3.5.8, npm/@vue/compiler-sfc@3.5.8, npm/@vue/compiler-ssr@3.5.8, npm/@vue/shared@3.5.8, npm/eslint-plugin-jsdoc@50.3.1, npm/get-east-asian-width@1.2.0, npm/get-func-name@2.0.2, npm/listr2@8.2.4, npm/magic-string@0.30.11, npm/package-json-from-dist@1.0.0, npm/rollup@4.22.4, npm/tsconfck@3.1.3, npm/typedoc@0.26.8, npm/vite-node@2.1.2, npm/vite@5.4.8, npm/vitest@2.1.2

View full report↗︎

@grypezgrypez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very clean 💯. I wonder if it would be preferable to declare the kernel specific errors in or next to the code that throws them. The constructors could then be more strongly typed (i.e. vatId: VatId instead of vatId: string), and whatever code imports the throwing routine can also import the error from the same place.

What do you think?

@sirtimid

sirtimid commented Oct 11, 2024

Copy link
Copy Markdown
MemberAuthor

VatId

@grypez We already went this path the first time and decided to move them on their own package so we have all the codes exported centrally in one place. But your point is valid and I am thinking that in order to avoid circular dependencies we will do more acrobatics like this, instead of having a types package (?) and problem solved for current and future endeavours.

grypez
grypez previously approved these changes Oct 11, 2024

@grypezgrypez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@rekmarksrekmarks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! Just some comments / minor suggestions.

Also a follow-up: #150

Comment threadpackages/errors/README.md Outdated
Comment threadpackages/errors/src/utils/asError.ts Outdated
Comment threadpackages/errors/src/errors.test.ts Outdated
Comment threadpackages/errors/src/constants.ts Outdated
Comment on lines +2 to +3
CaptpConnectionExists = 'CAPTP_CONNECTION_EXISTS',
CaptpConnectionNotFound = 'CAPTP_CONNECTION_NOT_FOUND',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These are only thrown by the vat. I think it would be virtuous if each error is associated with the component that throws it. Perhaps that's not feasible in practice (because the same error can be thrown in multiple places). What do you think?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I named this thinking that it can be used elsewhere, but it also makes sense to have distinct errors for each component, even if they refer to errors of the same service. I renamed it.

@rekmarksrekmarks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, one minor thing we should settle on actually:

This PR capitalizes "CapTP" differently in different places. We should determine our canonical capitalization, and apply that across the entire repo with a find-and-replace.

I think the least bad / most conventional option for MM is capTp / CapTp, and I recommend applying that. We can live with imports from endo being CapTP.

If we go for CapTP as our capitalization, we should avoid names that start with "CapTP" because capTP looks stupid. 😛

@sirtimidsirtimid mentioned this pull request Oct 14, 2024
Comment threadpackages/errors/src/errors.ts Outdated
Comment on lines +18 to +42
export class SupervisorReadError extends BaseError {
constructor(supervisorId: string, originalError: Error) {
super(
ErrorCode.SupervisorReadError,
'Unexpected read error from Supervisor.',
{
supervisorId,
},
originalError,
);
}
}

export class VatReadError extends BaseError {
constructor(vatId: string, originalError: Error) {
super(
ErrorCode.VatReadError,
'Unexpected read error from Vat.',
{
vatId,
},
originalError,
);
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm wondering if it's worthwhile to differentiate between stream read errors based on where they occur. Perhaps we should create a StreamReadError and let the stack trace / data property identify the location?

For instance, we could have data as:

typeLocation={vat: VatId}|{supervisor: SupervisorId};typeData={location: Location};

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

That sounds reasonable 👍

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Done 21d92c1

@rekmarks

Copy link
Copy Markdown
Member

See previous inline comment, then I otherwise only have this nit: #156

@sirtimid

Copy link
Copy Markdown
MemberAuthor

See previous inline comment, then I otherwise only have this nit: #156

@rekmarks Haven't I replaced all occurrences to CapTp already? What did I miss?

@rekmarks

Copy link
Copy Markdown
Member

@sirtimid it's truly an Über-nit, but from the description of #156:

The least bad option for code is to capitalize "CapTP" as CapTp, but in docs we should adhere to the "official" capitalization.

@sirtimid

Copy link
Copy Markdown
MemberAuthor

@sirtimid it's truly an Über-nit, but from the description of #156:

The least bad option for code is to capitalize "CapTP" as CapTp, but in docs we should adhere to the "official" capitalization.

done 3f849a5

@rekmarksrekmarks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@sirtimid
sirtimid merged commit fc39727 into mainOct 15, 2024
@sirtimid
sirtimid deleted the sirtimid/custom-error-classes branch October 15, 2024 22:53
sirtimid added a commit that referenced this pull request Oct 17, 2024
closes#150 Following #149, this PR
modifies the marshaling functions in `@ocap/streams` such that errors
from `@ocap/errors` are unmarshaled into their respective classes, based
on the error code. It also extends the `stringify` utility to support
ocap errors.
Sign up for freeto 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.

Introduce Custom Error Classes with Error Codes

3 participants

@sirtimid@rekmarks@grypez