Get the latest tech news

Why Use Structured Errors in Rust Applications?


Going against the common wisdom of “using anyhow for applications”.

If you google “error handling in Rust”, the typical introductory posts are going to start with the basics of panic, Option and Result, then explain these two libraries, give this rule of thumb to choose bethween them, show some code, and stop right here. Custom error types allow you to see all potential failure modes of a function at a glance, without (recursively) inspecting its implementation or maintaining fragile hand-written docs that can’t be fully trusted anyway. In a code review, you can easily notice when some error variant doesn’t make sense and should be handled locally, or comes from an action that shouldn’t be performed at all.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Structured Errors

Structured Errors

Photo of rust applications

rust applications

Related news:

News photo

Structured Errors in Go (2022)