oxidecomputer / oxidecomputer/crucible

`anyhow::Result` shouldn't be used for libraries

Open
#85 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

mvp
Dominant language
Rust
Stars
260
Forks
34
Avg merge
2d 1h
Merged PRs (30d)
8

Description

As per https://github.com/oxidecomputer/meta/blob/master/engineering/rust-crate-zoo.adoc#anyhow:

The anyhow crate provides useful error handling for applications. The main features are:

anyhow::Result<T> as a general return type, with the neccesary impls to be able to "`?` all the things."

A .context method to help troubleshooting later.

This lines up with application use-cases because in applications, you are often collecting errors from your dependencies, and need to combine and/or propogate them upwards. You often are not writing your own bespoke error types.

Anyhow requires an allocator, and therefore, is not appropriate for most of Oxide’s no_std code.

If you’re writing a library, see thiserror instead.

and https://github.com/oxidecomputer/meta/blob/master/engineering/rust-crate-zoo.adoc#thiserror:

The thiserror crate provides a nice derive for the Error trait. This makes it very useful when writing a library, as you’ll probably be crafting specific errors to return to your callers.

We need to switch upstairs code to return the standard Result instead of anyhow::Result.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the “upstairs” code and all uses of anyhow::Result in the repository, then review the referenced Rust crate guidance. The work is done when the relevant library code returns standard Result types instead of anyhow::Result, with existing behavior preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.