Git Product home page Git Product logo

Comments (2)

TimDiekmann avatar TimDiekmann commented on June 12, 2024 1

Hi @Tohman21 and thanks for filing the issue.

TL;DR: This is blocked by the specialization feature.

I'd love to implement Error for Report but currently that's sadly not possible for a few reasons:

  • (major) With an upcoming change we remove IntoReport, which implies impl<T, C: Context> ResultExt for Result<T, C>. Implementing Error for Report would imply a conflicting implementation. It's likely, that this can be solved with feature(specialization) enabled, but I have not tested this, yet. If this would be a breaking change this is fine as we want to adjust other parts of the API as soon as specialization is possible (e.g. merging attach and attach_printable).
  • (major) If Error is implemented on Report it's expected that Error::source is behaving correctly. As error-stack supports multiple source errors, the mapping does not work correctly. We're planning some overhaul for this "related-errors" feature in the near future and I will definitely will keep this issue in mind.
  • (probably the hardest issue to solve) It's easily possible to create Report<Report<E>>, which results in unexpected behavior, annoying errors, and hard-to-debug issues. It's simply not what people want to use. This cannot easily be solved without some kind of negative trait bounds which, AFAIK, is nothing that is immediately planned right now. Possibly it's possible to solve this via specialization, though.
  • (minor) There is a conflicting implementation between the From conversion of Report<E> and Box<dyn Error> when Error is implemented for Report<E>, but if anything like this is going to be added, we'd probably implement Context for Report<E: 'static> instead to be more generic. This is probably not a big issue but another annoyance when dealing with the Error trait. Ultimately we probably going to remove the Context trait when core::error::Error is stabilized but that's not fully decided yet as Context is potentially more generic than Error semantically.

One other possible route would also be to not remove IntoReport, yet, but rather try to implement Error on Report earlier (I don't expect specialization to be stabilized soon), but we still need to figure out the other issues first. However, with IntoReport and Report<E>: Error creating Report<Report<E>> is very easy by calling Result<T, Report<E>>::into_report(). We even have a dedicated test case to forbid this:

let result = Err::<(), _>(RootError);
let _: Result<(), Report<RootError>> = result.into_report();
let result = Err::<(), _>(Report::new(RootError));
// Not allowed
let _ = result.into_report();

it's possible that one of the listed issues is not really an issue or that I forgot something but it's definitely not easily possible now - and I'm very sad about this! We'd be very happy to hear more thoughts about this as well!

Happy to hear some thoughts from @indietyp as well.

from hash.

Tohman21 avatar Tohman21 commented on June 12, 2024

Thanks for quick answer. Yep, the problem is deeper than I thought

from hash.

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.