Skip to content

Conversation

@sirtimid
Copy link
Contributor

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 owner October 11, 2024 13:46
@socket-security
Copy link

socket-security bot commented Oct 11, 2024

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

Package New capabilities Transitives Size Publisher
npm/@es-joy/jsdoccomment@0.49.0 None 0 121 kB brettz9
npm/@lavamoat/allow-scripts@3.3.0 Transitive: environment, filesystem +2 161 kB
npm/@rollup/rollup-android-arm-eabi@4.24.0 None 0 1.46 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-android-arm64@4.24.0 None 0 2.06 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-darwin-arm64@4.24.0 None 0 2.18 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-darwin-x64@4.24.0 None 0 2.33 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-arm-gnueabihf@4.24.0 None 0 2.22 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-arm-musleabihf@4.24.0 None 0 2.22 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-arm64-gnu@4.24.0 None 0 2.2 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-arm64-musl@4.24.0 None 0 2.12 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-powerpc64le-gnu@4.24.0 None 0 2.76 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-riscv64-gnu@4.24.0 None 0 2.25 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-s390x-gnu@4.24.0 None 0 3.84 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-x64-gnu@4.24.0 None 0 2.46 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-linux-x64-musl@4.24.0 None 0 2.46 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-win32-arm64-msvc@4.24.0 None 0 2.76 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-win32-ia32-msvc@4.24.0 None 0 2.53 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@rollup/rollup-win32-x64-msvc@4.24.0 None 0 3.28 MB guybedford, lukastaegert, rich_harris, ...1 more
npm/@types/node@18.19.55 None 0 2.02 MB types
npm/@vitest/coverage-v8@2.1.3 None 0 114 kB vitestbot
npm/@vitest/expect@2.1.3 None 0 150 kB antfu, oreanno, patak, ...1 more
npm/@vitest/mocker@2.1.3 None +1 139 kB vitestbot
npm/@vitest/pretty-format@2.1.3 environment 0 45.5 kB vitestbot
npm/@vitest/runner@2.1.3 None 0 88.9 kB antfu, oreanno, patak, ...1 more
npm/@vitest/snapshot@2.1.3 None 0 85.2 kB antfu, oreanno, patak, ...1 more
npm/@vitest/spy@2.1.3 None 0 19.1 kB antfu, oreanno, patak, ...1 more
npm/@vitest/utils@2.1.3 None 0 155 kB antfu, oreanno, patak, ...1 more
npm/@vue/compiler-core@3.5.12 None 0 618 kB soda, yyx990803
npm/@vue/compiler-dom@3.5.12 None 0 640 kB soda, yyx990803
npm/@vue/compiler-sfc@3.5.12 None 0 2.48 MB soda, yyx990803
npm/@vue/compiler-ssr@3.5.12 None 0 47.3 kB soda, yyx990803
npm/@vue/shared@3.5.12 None 0 86.5 kB soda, yyx990803
npm/eslint-plugin-jsdoc@50.4.0 filesystem +2 2.1 MB gajus
npm/get-east-asian-width@1.3.0 None 0 15.7 kB sindresorhus
npm/listr2@8.2.5 None +2 305 kB cenk1cenk2
npm/magic-string@0.30.12 None 0 464 kB antfu
npm/package-json-from-dist@1.0.1 None 0 36.5 kB isaacs
npm/rollup@4.24.0 None 0 2.59 MB eventualbuddha, lukastaegert, rich_harris, ...2 more
npm/tsconfck@3.1.4 None 0 69.5 kB dominik_g
npm/typedoc@0.26.9 None +1 2.45 MB typedoc-bot
npm/vite-node@2.1.3 None 0 204 kB antfu, oreanno, patak, ...1 more
npm/vite@5.4.9 None 0 3.26 MB antfu, patak, soda, ...2 more
npm/vitest@2.1.3 environment, eval 0 1.68 MB vitestbot

🚮 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↗︎

Copy link
Contributor

@grypez grypez left a comment

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
Copy link
Contributor Author

sirtimid commented Oct 11, 2024

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.

@sirtimid sirtimid requested a review from rekmarks October 11, 2024 16:52
grypez
grypez previously approved these changes Oct 11, 2024
Copy link
Contributor

@grypez grypez left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@rekmarks rekmarks left a comment

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 on lines 2 to 3
CaptpConnectionExists = 'CAPTP_CONNECTION_EXISTS',
CaptpConnectionNotFound = 'CAPTP_CONNECTION_NOT_FOUND',
Copy link
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
Contributor Author

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.

Copy link
Member

@rekmarks rekmarks left a comment

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. 😛

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
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:

type Location = { vat: VatId } | { supervisor: SupervisorId };
type Data = { location: Location };

Copy link
Contributor Author

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
Contributor Author

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
Member

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

@sirtimid
Copy link
Contributor Author

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?

@sirtimid sirtimid requested a review from rekmarks October 15, 2024 22:06
@rekmarks
Copy link
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
Contributor Author

@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

Copy link
Member

@rekmarks rekmarks left a comment

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 main Oct 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 free to 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

4 participants