# Helper for passing extra context to Errors

**URL:** <https://internals.rust-lang.org/t/helper-for-passing-extra-context-to-errors/20259>\
**Category:** libs\
**Created:** [February 4, 2024, 11:08am UTC](https://internals.rust-lang.org/t/helper-for-passing-extra-context-to-errors/20259 "2024-02-04T11:08:56Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![Jon-Davis](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jon-davis/32/5453_2.png) [@Jon-Davis](https://internals.rust-lang.org/u/Jon-Davis)\
**Post date:** [February 6, 2024, 5:33am UTC](https://internals.rust-lang.org/t/helper-for-passing-extra-context-to-errors/20259/12 "2024-02-06T05:33:01Z")

</div>

I imagine this could be adapted to use the same pattern as `with_context`

```rust
let file = open(config_file)
  .with_zip_err(|| format!("Opening config file '{config_file}'"))?;

```

with a `thiserror` style Error of

```rust
#[derive(Error, Debug)]
enum Error {
    #[error("IO Error of: {0} with context of {1:?}")]
    Io(#[from] std::io::Error, #[context] Option<String>)
}

```

---

_[View the full topic](https://internals.rust-lang.org/t/helper-for-passing-extra-context-to-errors/20259)._
