Hacker News new | ask | show | jobs
by Yoric 990 days ago
For what it's worth, in Rust, this pretty much translates to

   some_operation(&arg)
      .with_context(|| format!("Some operation failed: {arg}"))?;
or, in most cases, the shorter

   some_operation(&arg)
      .context("Some operation failed")?;
If you forgot to call `with_context` and simply write

   some_operation(&arg)?;
the error is still propagated, it's just missing whatever context you wanted to add.

Whether that's better or worse than the Go snippet is something I'll let the reader decide.