instructure / paseto

A paseto implementation in rust.
MIT License
151 stars 14 forks source link

std::error::Error #27

Closed vbfox closed 4 years ago

vbfox commented 4 years ago

Motivation

Errors exposed are currently using the failure crate but recent Rust releases have stabilized std::error::Error, this PR is a proposal to change the errors to implement the standard trait using the derive implementation of the thiserror crate.

I also took the liberty to add a few more details to errors and refactor things to use map_error/ok_or and other functions a little more.

Test Plan

Ran cargo test

Discussion points

Mythra commented 4 years ago

Hey,

Thanks for this PR! Unfortunately I don't see much benefit in the actual content of this PR. So I'm going to have to turn it down at least for the reasons provided. It is still possible to get: std::error::Error from a failure type with the compat method: https://docs.rs/failure/0.1.6/failure/struct.Error.html#method.compat . So it's not like this PR gives us something we can't do. It seems to be switching from one style to another just because one is preferred by you. If there was a compelling reason, that just wasn't mendioned I'd personally prefer anyhow, or waiting for: https://github.com/yaahc/eyre to become a bit more stabilized. (but I don't yet see a reason to switch over to those). I also am against changing everything to map_err/map_ok. This is again a style change without any particular benefit in runtime, maintainability, or build cost.

I'd like to re-iterate I really appreciate all the work you've been putting into this library, and hope that you will continue to as time goes on. But at the same time please do not file PRs that cannot point to concrete benefits or differences.

For example this PR was opened with the motivation:

Errors exposed are currently using the failure crate but recent Rust releases have stabilized std::error::Error, this PR is a proposal to change the errors to implement the standard trait using the derive implementation of the thiserror crate.

But this isn't actually a motivating factor. You're telling me what was done, but not why. Failure can already desugar to std::error::Error with the compat method. In the motivation you should explain what concrete benefit we are getting out of this. Just because there are two ways of doing something doesn't mean we should switch from one to the other if it doesn't get us anything. Just because someone says it's more "idiomatic" doesn't matter to me if it's not giving me a benefit in runtime, compile time, long term maintainability, or stability.

Mythra commented 4 years ago

I should also mention even if this PR is closed, and we decide there is no benefit in say switching to anyhow/eyre, if you'd like to file a PR changing the error messages to your more helpful variants I would welcome that. Better error messages for developers are a tangible benefit, and would be welcome.

vbfox commented 4 years ago

I think we'll have to agree to disagree in the end because I disagree with quite a bit:

Mythra commented 4 years ago

You did actually outline one benefit here I agree with, Unfortunately this PR did not outline it. Specifically:

That is a tangible thing a user can get. A user can get a backtrace when using standard error. I still don't particularly like thiserrors' implementation, but I'd be open to other ideas.