supermacro / neverthrow

Type-Safe Errors for JS & TypeScript
MIT License
4.03k stars 84 forks source link

Add custom message to _unsafeUnwrap* #590

Open dmmulroy opened 1 month ago

dmmulroy commented 1 month ago

Pull Request Description

Summary

This PR introduces enhancements to the error handling mechanism within the codebase by allowing custom error messages to be specified. Additionally, it updates the README documentation and adds new test cases.

Changes Made

  1. README.md:

    • Added documentation on how to conditionally add a custom error message that will propagate with the error object.
    • Provided an example to demonstrate the usage of the custom error message with a stack trace.
  2. src/_internals/error.ts:

    • Updated the ErrorConfig interface to include an optional message property.
  3. src/result.ts:

    • Modified the _unsafeUnwrapErr method in the Ok class to use the custom error message if provided, otherwise, it defaults to the existing message.
    • Updated the _unsafeUnwrap method in the Err class to use the custom error message if provided, otherwise, it defaults to the existing message.
  4. tests/index.test.ts:

    • Added test cases to verify that custom error messages are correctly included when _unsafeUnwrap and _unsafeUnwrapErr are called with a custom message in the Ok and Err classes.
changeset-bot[bot] commented 1 month ago

🦋 Changeset detected

Latest commit: 72e0a7ca0f37d2d685efd5d8117f1815a0311afd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ---------- | ----- | | neverthrow | Minor |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

dmmulroy commented 1 month ago

@supermacro rebased on to master and added a changeset. This is the same work as #558

supermacro commented 4 weeks ago

safe to close this, right?

dmmulroy commented 5 days ago

Ope yup sorry, this notification got buried - will update tomorrow!