Code Monkey home page Code Monkey logo

Comments (3)

zkat avatar zkat commented on September 28, 2024

Hi! Thanks for the lovely, thoughtful issue! I'm honestly fairly new to Rust and haven't gotten used to how error patterns are supposed to written.

My first thought is that this should re-export anyhow::Error to start.

Or maybe the expected pattern is to have users just expect impl std::error::Error? What would work best for you, since you're an actual user? I don't mind making breaking changes!

from cacache-rs.

UhhhWaitWhat avatar UhhhWaitWhat commented on September 28, 2024

Thanks for your quick response. I am also new to Rust and currently in the exactly same boat as you in regards to error handling.

For my current use case I just need the ability to wrap cacaches errors and an exposed anyhow error would solve that issue nicely. I am not sure if tying your major version to that of anyhow is worth it though.
Consumers would also have no ability to distinguish between error types (I guess EntryNotFound might be very useful e.g.).

What I have seen in other library crates is to expose an error enum with specific, relevant members and wrap any underlying errors inside of it (which I think was your original approach).
The big tradeoff seems to be being able to treat all errors the same and therefore being able to easily add context vs. clearly communicating error states to the outside world. The author of the thiserror and anyhow crates apparently draws the line between "application" and library crates: https://github.com/dtolnay/anyhow#comparison-to-thiserror

In my own code I would probably resort to using a backtrace (which thiserror can attach automatically) to figure out the callchain and wrap errors of underlying libraries manually. And if additional context for an error type is important, add an additional entry to the error enum.
I am not sure how important custom error context is to you. If you don't mind replacing it with a backtrace for the general case, I would attempt the above approach in a PR to see how it feels.

Edit:
I just realised, std::backtrace is nightly only, so that might be a dealbreaker.

from cacache-rs.

zkat avatar zkat commented on September 28, 2024

closed by #24 :)

from cacache-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.