Skip to content
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

feat(assert): store original message in AssertionError #38

Merged

Conversation

psychedelicious
Copy link
Contributor

AssertionError wraps the message provided during instantiation with some additional text:

const error = new AssertionError("message");
console.log(error.message); // 'Wrong assertion encountered: "message"'

This helpfully communicates that the error resulted from a failed assertion.

Sometimes we want to access the original message without the wrapper text. For example, we may wish to surface the error directly to a user.

This change adds an originalMessage property to AssertionError to store the original message without any wrapper text.

The existing behaviour is unchanged, but library consumers now have access to the original message.

Closes #35

@garronej
Copy link
Owner

garronej commented Nov 8, 2024

Looks perfect

Can you fix the conflict?

`AssertionError` wraps the message provided during instantiation with some additional text:

```ts
const error = new AssertionError("message");
console.log(error.message); // 'Wrong assertion encountered: "message"'
```

This helpfully communicates that the error resulted from a failed assertion.

Sometimes we want to access the original message without the wrapper text. For example, we may wish to surface the error directly to a user.

This change adds an `originalMessage` property to `AssertionError` to store the original message without any wrapper text.

The existing behaviour is unchanged, but library consumers now have access to the original message.

Closes garronej#35
@psychedelicious psychedelicious force-pushed the psyche/feat/original-message branch from 1817ed7 to 538da12 Compare November 8, 2024 20:07
@psychedelicious
Copy link
Contributor Author

Thanks! Fixed the conflict.

@garronej garronej enabled auto-merge November 9, 2024 08:21
@garronej garronej disabled auto-merge November 9, 2024 08:30
@garronej garronej merged commit 04afa8b into garronej:main Nov 9, 2024
7 checks passed
@garronej
Copy link
Owner

garronej commented Nov 9, 2024

Thank you! I have released a new version

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.

AssertionError.message is not the original message
2 participants