frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Show HN: Stack Error – ergonomic error handling for Rust

https://github.com/gmcgoldr/stackerror
24•garrinm•7h 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•5h 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•5h 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•5h ago
I still prefer the Anyhow solution, but I like the approach here.
IshKebab•4h ago
Isn't this strictly superior to Anyhow? What do you like more about Anyhow?
garrinm•36m 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•4h 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•38m 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•4h 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•30m 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!

The macros are used for two purposes: one is (as you pointed out) to include this information in the string. The other is to reduce the amount of boilerplate closures in operations like `.map_err(|x| StackError::new(x))`. I think using `track_caller` I can make a cleaner separation here and use macros just to reduce the boilerplate.

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

Thank you for the insights.

France Becomes First Government to Endorse UN Open Source Principles

https://social.numerique.gouv.fr/@codegouvfr/114529954373492878
269•bzg•3h ago•59 comments

Spaced repetition systems have gotten better

https://domenic.me/fsrs/
708•domenicd•14h ago•420 comments

New research reveals the strongest solar event ever detected, in 12350 BC

https://phys.org/news/2025-05-reveals-strongest-solar-event-bc.html
26•politelemon•3d ago•2 comments

Show HN: I modeled the Voynich Manuscript with SBERT to test for structure

https://github.com/brianmg/voynich-nlp-analysis
275•brig90•9h ago•85 comments

Ditching Obsidian and building my own

https://amberwilliams.io/blogs/building-my-own-pkms
235•williamsss•9h ago•269 comments

Show HN: Vaev – A browser engine built from scratch (It renders google.com)

https://github.com/skift-org/vaev
129•monax•8h ago•53 comments

$30 Homebrew Automated Blinds Opener

https://sifter.org/~simon/journal/20240718.html
186•busymom0•8h ago•79 comments

There Are People Who Can See and Others Who Cannot Even Look

https://worldhistory.substack.com/p/there-are-people-who-can-see-and
7•crescit_eundo•1h ago•0 comments

Show HN: A platform to find tech conferences, discounts, and ticket giveaways

https://www.tech.tickets/
43•danthebaker•2d ago•12 comments

Spaced Repetition Memory System

https://notes.andymatuschak.org/Spaced_repetition_memory_system
163•gasull•10h ago•16 comments

Hyper Typing

https://pscanf.com/s/341/
44•azhenley•5h ago•40 comments

Comparing Parallel Functional Array Languages: Programming and Performance

https://arxiv.org/abs/2505.08906
52•vok•2d ago•9 comments

K-Scale Labs: Open-source humanoid robots, built for developers

https://www.kscale.dev/
55•rbanffy•6h ago•31 comments

The Journal of Imaginary Research

https://journalofimaginaryresearch.home.blog/
13•cenazoic•2d ago•2 comments

Show HN: Buckaroo – Data table UI for Notebooks

https://github.com/paddymul/buckaroo
82•paddy_m•10h ago•6 comments

Show HN: Python Simulator of David Deutsch’s "Constructor Theory of Time"

https://github.com/gvelesandro/constructor-theory-simulator
51•SandroG•5h ago•6 comments

KDE is finally getting a native virtual machine manager called "Karton"

https://www.neowin.net/news/kde-is-finally-getting-a-native-virtual-machine-manager-called-karton/
70•bundie•3h ago•18 comments

In Memoriam: John L. Young, Cryptome Co-Founder

https://www.eff.org/deeplinks/2025/05/memoriam-john-l-young-cryptome-co-founder
169•coloneltcb•3d ago•17 comments

Living beings emit a faint light that extinguishes upon death, study

https://phys.org/news/2025-05-emit-faint-extinguishes-death.html
16•pseudolus•1h ago•1 comments

Show HN: Hardtime.nvim – break bad habits and master Vim motions

https://github.com/m4xshen/hardtime.nvim
166•m4xshen•13h ago•66 comments

Emergent social conventions and collective bias in LLM populations

https://www.science.org/doi/10.1126/sciadv.adu9368
44•jbotz•9h ago•14 comments

Green Fabrication of Sulfonium-Containing Bismuth Materials for X-Ray Detection

https://advanced.onlinelibrary.wiley.com/doi/10.1002/adma.202418626
6•PaulHoule•3d ago•1 comments

Yahtzeeql – Yahtzee solver that's mostly SQL

https://github.com/charliemeyer/yahtzeeql
17•skadamat•3d ago•7 comments

Dezyne Programming Language

https://dezyne.org/dezyne/manual/dezyne/dezyne.html
30•aulisius•1d ago•5 comments

Mystical

https://suberic.net/~dmm/projects/mystical/README.html
362•mmphosis•1d ago•43 comments

How the humble chestnut traced the rise and fall of the Roman Empire

https://www.bbc.com/future/article/20250513-what-chestnuts-reveal-about-the-roman-empire
40•bookofjoe•4d ago•4 comments

How the Sun Enterprise 10000 was born (2007)

https://www.filibeto.org/aduritz/truetrue/e10000/how-e10k-wasborn.html
54•robin_reala•13h ago•54 comments

Building my childhood dream PC

https://fabiensanglard.net/2168/index.html
148•todsacerdoti•11h ago•66 comments

The Fall of Roam

https://every.to/superorganizers/the-fall-of-roam
90•ingve•7h ago•41 comments

AniSora: Open-source anime video generation model

https://komiko.app/video/AniSora
329•PaulineGar•1d ago•187 comments