Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 12, 2026

Adds optional anyhow feature to gix-error enabling conversion of Exn<T> and Error types to anyhow::Error with proper source chain preservation.

Changes

  • New IntoAnyhow trait - provides into_anyhow() method for converting to anyhow::Error

    • Implemented for both Exn<T> and Error
    • Uses trait pattern to avoid conflicts with anyhow's blanket From<E> implementation
  • Tree-to-chain flattening - recursively follows first child of each frame to create linear source chain

    • Preserves all error information in owned ChainedFrameError wrappers
    • Enables proper "Caused by:" formatting in anyhow output
  • Feature-gated module - src/anyhow.rs compiled only when anyhow feature enabled

Usage

use gix_error::{ResultExt, IntoAnyhow};

let result: Result<(), IoError> = Err(IoError("disk read failed"));
let result = result.or_raise(|| FileError("config.toml inaccessible"));
let result = result.or_raise(|| AppError("init failed"));

let anyhow_err = result.unwrap_err().into_anyhow();
// Prints:
// Error: init failed
// 
// Caused by:
//    0: config.toml inaccessible  
//    1: disk read failed

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 12, 2026 12:29
Add optional anyhow feature that provides IntoAnyhow trait to convert
both Exn<T> and Error types to anyhow::Error. The conversion flattens
the tree of error frames into a linear source chain, allowing anyhow
to print proper error chains with "Caused by:" formatting.

Co-authored-by: Byron <[email protected]>
- Use to_string() instead of format!() for Display conversion
- Remove unused import in test

Co-authored-by: Byron <[email protected]>
Copilot AI changed the title [WIP] Fix gix error punch-through issues Add anyhow integration to gix-error Jan 12, 2026
Copilot AI requested a review from Byron January 12, 2026 12:36
@Byron
Copy link
Member

Byron commented Jan 12, 2026

Missed the mark.

@Byron Byron closed this Jan 12, 2026
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