Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .depcheckrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ ignores:
- 'typedoc'
- 'typescript'
- 'typescript-plugin-css-modules'
- '@agoric/internal'
- 'setimmediate'
- '@types/setimmediate'

# Used by @ocap/nodejs to build the sqlite3 bindings
- 'node-gyp'
Expand Down
6 changes: 5 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const config = createConfig([
},

{
files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'],
files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts', '**/*.d.ts'],
extends: [metamaskTypescriptConfig],
rules: {
'@typescript-eslint/explicit-function-return-type': [
Expand All @@ -65,6 +65,10 @@ const config = createConfig([
// option and "import-x/consistent-type-specifiers" rule.
'@typescript-eslint/consistent-type-imports': 'off',
'import-x/consistent-type-specifier-style': ['error', 'prefer-top-level'],

// This should only be enable for JavaScript files.
// Ref: https://github.com/import-js/eslint-plugin-import/issues/2215#issuecomment-911245486
'import-x/unambiguous': 'off',
},
},

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"@ts-bridge/shims": "^0.1.1",
"@types/lodash": "^4.17.7",
"@types/node": "^22.10.1",
"@types/setimmediate": "^1.0.4",
"@types/webextension-polyfill": "^0",
"@typescript-eslint/eslint-plugin": "^8.8.1",
"@typescript-eslint/parser": "^8.8.1",
Expand Down Expand Up @@ -123,8 +124,10 @@
"cookie": "^0.7.0"
},
"dependencies": {
"@agoric/internal": "0.4.0-u18.0",
"@metamask/approval-controller": "^7.1.1",
"ava": "^6.2.0",
"setimmediate": "^1.0.5",
"webextension-polyfill": "^0.12.0"
}
}
2 changes: 0 additions & 2 deletions packages/errors/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export const ErrorStruct = define<Error>(
export enum ErrorCode {
StreamReadError = 'STREAM_READ_ERROR',
VatAlreadyExists = 'VAT_ALREADY_EXISTS',
VatCapTpConnectionExists = 'VAT_CAPTP_CONNECTION_EXISTS',
VatCapTpConnectionNotFound = 'VAT_CAPTP_CONNECTION_NOT_FOUND',
VatDeleted = 'VAT_DELETED',
VatNotFound = 'VAT_NOT_FOUND',
}
Expand Down
34 changes: 6 additions & 28 deletions packages/errors/src/errors/StreamReadError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@ import type { MarshaledOcapError } from '../types.js';

describe('StreamReadError', () => {
const mockVatId = 'mockVatId';
const mockSupervisorId = 'mockSupervisorId';
const mockOriginalError = new Error('Original error');

it('creates a StreamReadError for VatSupervisor with the correct properties', () => {
const error = new StreamReadError(
{ supervisorId: mockSupervisorId },
{ vatId: mockVatId },
{ cause: mockOriginalError },
);
expect(error).toBeInstanceOf(StreamReadError);
expect(error.code).toBe(ErrorCode.StreamReadError);
expect(error.message).toBe('Unexpected stream read error.');
expect(error.data).toStrictEqual({ supervisorId: mockSupervisorId });
expect(error.data).toStrictEqual({ vatId: mockVatId });
expect(error.cause).toBe(mockOriginalError);
});

it('creates a StreamReadError for Vat with the correct properties', () => {
it('creates a StreamReadError for VatHandle with the correct properties', () => {
const error = new StreamReadError(
{ vatId: mockVatId },
{ cause: mockOriginalError },
Expand All @@ -46,7 +45,7 @@ describe('StreamReadError', () => {
expect(error.cause).toBe(mockOriginalError);
});

it('unmarshals a valid marshaled StreamReadError for Vat', () => {
it('unmarshals a valid marshaled StreamReadError for VatHandle', () => {
const data = { vatId: mockVatId };
const marshaledError: MarshaledOcapError = {
[ErrorSentinel]: true,
Expand Down Expand Up @@ -77,7 +76,7 @@ describe('StreamReadError', () => {
});

it('unmarshals a valid marshaled StreamReadError for VatSupervisor', () => {
const data = { supervisorId: mockSupervisorId };
const data = { vatId: mockVatId };
const marshaledError: MarshaledOcapError = {
[ErrorSentinel]: true,
message: 'Unexpected stream read error.',
Expand All @@ -100,7 +99,7 @@ describe('StreamReadError', () => {
expect(unmarshaledError.message).toBe('Unexpected stream read error.');
expect(unmarshaledError.stack).toBe('customStack');
expect(unmarshaledError.data).toStrictEqual({
supervisorId: mockSupervisorId,
vatId: mockVatId,
});
expect(unmarshaledError.cause).toBeInstanceOf(Error);
expect((unmarshaledError.cause as Error).message).toBe('Original error');
Expand All @@ -121,25 +120,4 @@ describe('StreamReadError', () => {
'At path: data -- Expected the value to satisfy a union of `object | object | object`, but received: "invalid data"',
);
});

it('throws when both vatId and supervisorId are present in data', () => {
const marshaledError: MarshaledOcapError = {
[ErrorSentinel]: true,
message: 'Unexpected stream read error.',
stack: 'customStack',
code: ErrorCode.StreamReadError,
data: { supervisorId: mockSupervisorId, vatId: mockVatId },
cause: {
[ErrorSentinel]: true,
message: 'Original error',
stack: 'bar',
},
};

expect(() =>
StreamReadError.unmarshal(marshaledError, unmarshalErrorOptions),
).toThrow(
'At path: data -- Expected the value to satisfy a union of `object | object | object`, but received: [object Object]',
);
});
});
8 changes: 1 addition & 7 deletions packages/errors/src/errors/StreamReadError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ import {
} from '../constants.js';
import type { ErrorOptionsWithStack, MarshaledOcapError } from '../types.js';

type StreamReadErrorData =
| { vatId: string }
| { supervisorId: string }
| { kernelId: string };
type StreamReadErrorData = { vatId: string } | { kernelId: string };
type StreamReadErrorOptions = Required<ErrorOptions> &
Pick<ErrorOptionsWithStack, 'stack'>;

Expand All @@ -41,18 +38,15 @@ export class StreamReadError extends BaseError {
data: union([
object({
vatId: string(),
supervisorId: optional(never()),
kernelId: optional(never()),
}),
object({
supervisorId: string(),
vatId: optional(never()),
kernelId: optional(never()),
}),
object({
kernelId: string(),
vatId: optional(never()),
supervisorId: optional(never()),
}),
]),
cause: MarshaledErrorStruct,
Expand Down

This file was deleted.

52 changes: 0 additions & 52 deletions packages/errors/src/errors/VatCapTpConnectionExistsError.ts

This file was deleted.

This file was deleted.

51 changes: 0 additions & 51 deletions packages/errors/src/errors/VatCapTpConnectionNotFoundError.ts

This file was deleted.

Loading
Loading