Skip to content

feat: allow map_err like syntax on change_context#9070

Open
khanhtranngoccva wants to merge 2 commits into
hashintel:mainfrom
khanhtranngoccva:err-transform
Open

feat: allow map_err like syntax on change_context#9070
khanhtranngoccva wants to merge 2 commits into
hashintel:mainfrom
khanhtranngoccva:err-transform

Conversation

@khanhtranngoccva

Copy link
Copy Markdown

🌟 What is the purpose of this PR?

  • Add Report::current_context_mut to access the internal error mutably. This is required if the caller needs to modify or extract non-Clone fields as part of error recovery.
  • Add ResultExt::change_context_adaptive to allow map_err like syntax. This helps with cases of error propagation where the underlying error needs to be surfaced to the domain level in the current form or in another form.

🔍 What does this change?

  • Added Report::current_context_mut
  • Added ResultExt::change_context_adaptive

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing
  • modifies an npm-publishable library and I have added a changeset file(s)
  • modifies a Cargo-publishable library and I have amended the version
  • modifies a Cargo-publishable library, but it is not yet ready to publish
  • modifies a block that will need publishing via GitHub action once merged
  • I am unsure / need advice

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change
  • are in a state where docs changes are not yet required but will be
  • require changes to docs which are made as part of this PR
  • require changes to docs which are not made in this PR
    • Provide more detail here
  • I am unsure / need advice

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph
  • affected the execution graph, and the turbo.json's have been updated to reflect this
  • I am unsure / need advice

⚠️ Known issues

  • Compiler jank related to non-lexical lifetimes prevents embedding the report in case of a panic.

🐾 Next steps

  • Re-introduce the report embedding in the unreachable! panic in Report::current_context_mut

🛡 What tests cover this?

  • Test cases in test_change_context.rs and test_conversion.rs have been modified to cover these two functions.

❓ How to test this?

  • Running cargo test is sufficient, as these tests are fuzzed.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@CLAassistant

CLAassistant commented Jul 20, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cursor

cursor Bot commented Jul 20, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Small, additive public API on a published error-handling crate with focused tests; no auth or data-path changes.

Overview
Adds mutable access to the active error context and a Result extension for context changes that can read or modify the existing report before wrapping a new context—useful when fields are not Clone or need recovery (e.g. take() from the inner error).

Report::current_context_mut mirrors current_context via downcast_mut, with the same panic path if the typed context is missing (report text omitted in the panic message due to a known compiler limitation).

ResultExt::change_context_adaptive on Err builds the report, runs F: FnOnce(&mut Report<E::Context>) -> C, then applies change_context with the returned context—analogous to change_context_lazy but with access to the underlying report.

The crate is bumped to 0.8.1; tests use rand to assert preserved context values and resource extraction through the new APIs.

Reviewed by Cursor Bugbot for commit 47c732a. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions github-actions Bot added area/deps Relates to third-party dependencies (area) area/libs > error-stack Affects the `error-stack` crate (library) area/libs Relates to first-party libraries/crates/packages (area) area/tests New or updated tests labels Jul 20, 2026
@vercel

vercel Bot commented Jul 20, 2026

Copy link
Copy Markdown

@khanhtranngoccva is attempting to deploy a commit to the HASH Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/deps Relates to third-party dependencies (area) area/libs > error-stack Affects the `error-stack` crate (library) area/libs Relates to first-party libraries/crates/packages (area) area/tests New or updated tests

Development

Successfully merging this pull request may close these issues.

2 participants