supermacro / neverthrow

Type-Safe Errors for JS & TypeScript
MIT License
4.04k stars 85 forks source link

Add custom `message` field to `_unsafeUnwrap*` config object #558

Closed dmmulroy closed 1 month ago

dmmulroy commented 3 months 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 3 months ago

⚠️ No Changeset found

Latest commit: be9b9b7153a9bec0beaf6ea17c57ec571d15309d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

supermacro commented 2 months ago

Hey @dmmulroy thank you for the first contribution :) ... please provide a changeset file and additionally address the merge conflicts!

dmmulroy commented 1 month ago

Going to close this and reopen with fixes addressed, i made a silly mistake by pushing to my master branch