Skip to content

Add generic WithContext error#3

Merged
maxwase merged 2 commits into
masterfrom
add-with-context
May 16, 2026
Merged

Add generic WithContext error#3
maxwase merged 2 commits into
masterfrom
add-with-context

Conversation

@maxwase
Copy link
Copy Markdown
Owner

@maxwase maxwase commented May 16, 2026

Also WithPath and experimental Path display wrapper

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a generic WithContext<C, E, F> error wrapper that pairs an error with a context value and renders both via a static ContextFormat strategy (Colon by default, PathColon for path-aware contexts, plus a WithPath alias). Also introduces an experimental DisplayPath newtype, a new with_context example, README documentation, and conditional no_std doc handling in lib.rs.

Changes:

  • New WithContext<C, E, F> type with ContextFormat strategy trait, Colon/PathColon strategies, WithPath alias, and Error::source that skips the inner error to avoid duplication in chain walks.
  • New experimental DisplayPath<T> adapter and an end-to-end example showing nested WithContext layers used with MainResult/thiserror.
  • README section documenting WithContext/WithPath and a lib.rs tweak that switches between the README doc and a short fallback depending on the std feature.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/with_context.rs Introduces WithContext, ContextFormat, Colon/PathColon strategies, aliases, and tests.
src/path_display.rs Adds experimental DisplayPath<T> newtype adapting Path-like values to Display.
src/lib.rs Registers new modules/re-exports and gates the README doc on the std feature.
examples/with_context.rs End-to-end example combining nested WithContext with MainResult and thiserror.
README.md Adds "Adding context" section documenting WithContext/WithPath; minor rewording elsewhere.
Cargo.toml Marks the new with_context example as requiring the std feature.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md Outdated
Comment thread src/with_context.rs
@maxwase maxwase force-pushed the add-with-context branch from 9b034db to a365f8e Compare May 16, 2026 21:21
@maxwase maxwase merged commit 1f20a61 into master May 16, 2026
4 checks passed
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.

2 participants