frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Show HN: Stack Error – ergonomic error handling for Rust

https://github.com/gmcgoldr/stackerror
27•garrinm•1y ago
Stack Error reduces the up-front cost of designing an error handling solution for your project, so that you focus on writing great libraries and applications.

Stack Error has three goals:

1. Provide ergonomics similar to anyhow.

2. Create informative error messages that facilitate debugging.

3. Provide typed data that facilitates runtime error handling.

Comments

tevon•1y ago
This is awesome! Will give it a try in my next project.

How does it keep track of filename and line number in a compiled binary? I'm fairly new to rust libraries and this doesn't quite make sense to me. I know in JS you need a source-map for minification, how does this work for a compiled language?

fpoling•1y ago
Rust provides file!, line! and column! macros that expands into a compile-time constants that the compiler embeds then into the executable. This way no source map at runtime is necessary as the relevant errors are constructed from those constants.

Presumably StackError just uses those macros.

But for debugging a source map is still necessary and is a part of various debug formats.

rhabarba•1y ago
I still prefer the Anyhow solution, but I like the approach here.
IshKebab•1y ago
Isn't this strictly superior to Anyhow? What do you like more about Anyhow?
rhabarba•1y ago
I prefer Anyhow's non-intrusiveness: "Result" is still "Result" and all I need is a "?". I agree with Stack Error's documentation that Anyhow can't help with debugging that well, but it's "good enough" in my opinion.
IshKebab•1y ago
Result in `anyhow::Result` though. It's still a different type. Or do you literally mean you like that it is still spelt the same?

And I think you can still use `?` with this if you don't want to add any context... Not 100% sure on that though.

rhabarba•1y ago
Might as well be my limited understanding from what I can read behind the link, to be fair.
garrinm•1y ago
Anyhow still makes things easier for application development. The main drawback is that the resulting error type doesn't implement std::error::Error, so it's not suitable for library development (as pointed out in the anyhow documentation). Stack Error is a bit less ergonomic, but suitable for library development.
shepmaster•1y ago
I hope to read through your crate and examples later, but if you have a chance, I’d be curious to hear your take on how Stack Error differs from my library, SNAFU [1]!

[1]: https://docs.rs/snafu/latest/snafu/index.html

garrinm•1y ago
I played around a bit with SNAFU a couple of years ago, but I'm haven't worked deeply with the library so there might well be some features I'm not aware of.

I think SNAFU is more like a combination of anyhow and thiserror into a single crate, rather than Stack Error which leans more heavily into the "turnkey" error struct. Using the Whatever struct, you get some overlap with Stack Error features:

- Error message are co-located.

- Error type implement std::error::Error (suitable for library development).

- External errors can be wrapped and context can easily be added.

Where Stack Error differs:

- Error codes (and URIs) offer ability for runtime error handling without having to compare strings.

- Provides pseudo-stack by stacking messages.

Underlying this is an opinion I baked into Stack Error: error messages are for debugging, not for runtime error handling. Otherwise all your error strings effectively become part of your public interface since a downstream library can rely on them for error handling.

lilyball•1y ago
If the macros only exist to get file and line information, you could do the same thing by using `#[track_caller]` functions combined with `std::panic::Location` to get that same info. For example, `stack_err!` could be replaced with

  impl StackError {
      #[track_caller]
      fn new_location(msg: impl Display) -> Self {
          let loc = std::panic::Location::caller();
          Self::new(format!("{}:{} {msg}", loc.file(), loc.line()))
      }
  }
such that you call `.map_err(StackError::new_location("data is not a list of strings"))`. A macro is nice if you need to process format strings with arguments (though someone can call `StackError::new_location(format_args!(…))` if they want), but all of your examples show static strings so it's nice to avoid the error in that case.

The use of `std::panic::Location` also means instead of baking that into a format string you could also just have that be an extra field on the error, which would let you expose accessors for it, and you can then print them in your Debug/Display impls.

Speaking of, the Display impl really should not include its source. Standard handling for errors expects that an error prints just itself with Display because it's very common to recurse through sources and print those, so if Display prints the source too then you're duplicating output. Go ahead and print it on Debug though, that's nice for errors returned from `main()`.

garrinm•1y ago
Thanks for the insight, I wasn't aware of `track_caller`. I'll definitely be looking into this. I was scratching my head trying to figure out how to make file and line number usage consistent and customizable, this looks like the answer!

You're also right that this will pretty much eliminate the need for macros.

That's also a very key insight about Display vs. Debug printing. I'll be looking into that as well.

Thank you for the thoughtful reply.

DavidWilkinson•1y ago
Dei here, from the team behind Error Stack [1] (a similarly named existing, context-aware error-handling library for Rust that supports arbitrary attachments). How does Stack Error, here, compare?

[1]: https://crates.io/crates/error-stack

Default Bias: Who chose your settings?

https://designexplained.substack.com/p/default-bias-who-chose-your-settings
1•kaizenb•2m ago•0 comments

Show HN: Integrated Music Composition

https://bookerapp.replit.app/book/music-composition/
1•ersinesen•3m ago•0 comments

Intel: Our upcoming AI chip will be cheaper, run cooler than Nvidia, AMD options

https://arstechnica.com/ai/2026/06/intel-our-upcoming-ai-chip-will-be-cheaper-run-cooler-than-nvi...
2•tambourine_man•3m ago•0 comments

CVE-2026-41089

https://gemini.google.com/share/ab8ed0f5c0ec
1•redog•4m ago•1 comments

Did Lab Insects Learned That the Smell of DEET Would Lead Them to a Tasty Treat?

https://www.smithsonianmag.com/smart-news/could-bug-spray-attract-mosquitoes-lab-insects-learned-...
1•Vaslo•6m ago•0 comments

A per-project open-source Claude Code skill manager

https://github.com/narendranag/skillkit
2•narendranag•7m ago•1 comments

Michael Burry Just Called Nvidia's SpaceX Chip Deal 'Fugazi.'

https://247wallst.com/investing/2026/06/01/michael-burry-just-called-nvidias-spacex-chip-deal-fug...
4•johnbarron•9m ago•1 comments

People with less common surnames tend to live longer [pdf]

https://faculty.econ.ucdavis.edu/faculty/gclark/The%20Son%20Also%20Rises/Pena%20Surname%20Frequen...
2•bilsbie•10m ago•0 comments

Kafka Partitions are the wrong ordering abstraction. Keys are

https://medium.com/conduktor/kafka-partitions-are-the-wrong-ordering-abstraction-keys-are-b54dc5b...
1•chtefi•11m ago•0 comments

Fuzzy Time Everywhere

https://www.nedrichards.com/2026/05/fuzzy-time-everywhere/
1•eustoria•11m ago•0 comments

Leptos Status Update – May 2026

https://github.com/leptos-rs/leptos/issues/4707
1•dabinat•11m ago•0 comments

It is as if you were doing work

https://pippinbarr.com/itisasifyouweredoingwork/
1•eustoria•12m ago•0 comments

Love's Labour Lost – Building a Reading App

https://tech.stonecharioteer.com/posts/2026/loves-labour-lost/
3•stonecharioteer•12m ago•0 comments

Israel doing everything to derail diplomacy by turning Lebanon into another Gaza

https://www.commondreams.org/news/israel-lebanon-war
2•johnbarron•13m ago•0 comments

US says ban on AI chip shipments applies to Chinese firms outside China

https://www.aljazeera.com/economy/2026/6/1/us-says-ban-on-ai-chip-shipments-applies-to-chinese-fi...
4•billybuckwheat•16m ago•0 comments

DelphiTools: A collection of small, low stakes and low effort tools

https://delphi.tools/
4•eustoria•17m ago•0 comments

I can build anything and reach no-one

https://twitter.com/jackthinkz/status/2061432223035765207
1•jack_lynch•19m ago•1 comments

Woojer Vest 4: It's like THX for your torso

https://newatlas.com/consumer-tech/woojer-vest-4-review/
1•dabinat•21m ago•0 comments

Why Larger Models Learn More: Capacity, Interference, Rare-Task Retention

https://arxiv.org/abs/2605.29548
1•matt_d•21m ago•0 comments

Can the stockmarket swallow Anthropic, SpaceX and OpenAI?

https://economist.com/finance-and-economics/2026/06/01/can-the-stockmarket-swallow-anthropic-spac...
2•andsoitis•22m ago•1 comments

Most enterprise AI projects have the training data they need

https://www.scribeitlocal.com/meeting-transcripts-for-ai-agents.html
1•JankoTech•23m ago•0 comments

A just wrapper for tmux and global recipes

https://eshlox.net/just-wrapper
1•speckx•26m ago•0 comments

PyTorch's playbook for AI coding, as of May 2026

https://docs.pytorch.org/devlogs/ai-agents/2026-05-30-ai-coding-playbook/
2•matt_d•26m ago•0 comments

Which AI coding tools do AIs recommend? Data across 10 models and 1000 responses

https://tryrenown.com/research/ai-visibility-ai-coding-tools/full/
1•shmval•27m ago•1 comments

Show HN: Kios – An iOS e-reader app with kobo, kosync and OPDS support

https://testflight.apple.com/join/fzdZFbtM
2•raphi011•30m ago•0 comments

Leaked Docs Suggest Trump Admin Running Covert Influence Campaigns on Americans

https://weaponizedspaces.substack.com/p/leaked-docs-suggest-trump-admin-is
7•rbanffy•31m ago•0 comments

Show HN: Datapoint AI – fastest way to know what your customers want

https://trydatapoint.com
2•yoloakki•31m ago•0 comments

Pogroms, American Style

https://paulkrugman.substack.com/p/pogroms-american-style
5•rbanffy•32m ago•0 comments

Games in which you walk (2019)

https://p.migdal.pl/blog/2019/06/games-in-which-you-walk-and-get-immersed/
1•stared•32m ago•0 comments

After 19 Years, Quetoo Is Here

https://quetoo.org/news/quetoo-is-here/
2•klaussilveira•33m ago•0 comments