Skip to content

Conversation

@sirtimid
Copy link
Contributor

closes #169

This PR addresses the issue where Ocap errors had their properties stack and cause assigned incorrectly after hardening, which went unnoticed in tests due to mocking of the harden function.

The properties stack and cause are now assigned before hardening the error.

The unmarshalErrorOptions function is introduced to properly unmarshal and assign the error options, ensuring that the properties are correctly handled during the unmarshaling process.

Refactored unmarshalError to ensure the correct unmarshaling of properties before hardening.

Custom error classes adjusted to utilize unmarshalErrorOptions when unmarshaling error instances.

The tests have been updated to remove the mocked harden function, ensuring that the properties are correctly assigned and the hardened objects behave as expected.

@sirtimid sirtimid requested a review from a team as a code owner October 21, 2024 20:25
@sirtimid sirtimid requested review from grypez and rekmarks October 21, 2024 20:25
@@ -0,0 +1,16 @@
import '@ocap/shims/endoify';
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 know we’re already importing it via the setupFiles option in the Vitest config, but I’m explicitly importing it here for clarity. It doesn’t hurt, right? :)

Copy link
Contributor

Choose a reason for hiding this comment

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

If clarity is good here, would it not also be good in the other tests, too? :)

For my part I think this is a fine canary to sing about changes to vitest.config.ts and nothing need be changed. I just don't think it's a clarity issue, and we can reasonably expect reviewers and developers to be familiar with the contents of setupFiles in the package's vitest.config.ts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are not wrong :) I guess it's not needed.

grypez
grypez previously approved these changes Oct 22, 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.

Small invitations for discussion, but LGTM.

export function unmarshalErrorOptions(
marshaledError: MarshaledError,
): ErrorOptionsWithStack {
const output: ErrorOptionsWithStack = { stack: marshaledError.stack ?? '' };
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const output: ErrorOptionsWithStack = { stack: marshaledError.stack ?? '' };
const output: ErrorOptionsWithStack = { stack: marshaledError.stack };

The type you define allows stack to be undefined. Why do you prefer to default to the empty string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I wrote it better.

@@ -0,0 +1,16 @@
import '@ocap/shims/endoify';
Copy link
Contributor

Choose a reason for hiding this comment

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

If clarity is good here, would it not also be good in the other tests, too? :)

For my part I think this is a fine canary to sing about changes to vitest.config.ts and nothing need be changed. I just don't think it's a clarity issue, and we can reasonably expect reviewers and developers to be familiar with the contents of setupFiles in the package's vitest.config.ts.

@sirtimid sirtimid merged commit bcef026 into main Oct 22, 2024
@sirtimid sirtimid deleted the sirtimid/ocap-error-stack branch October 22, 2024 16:46
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.

bug(errors): Stack can't be set after importing @ocap/shims/endoify.

3 participants