the trait `std::error::Error` is not implemented for `digest_auth::error::Error` #3

Closed
opened 5 years ago by Ghost · 6 comments
Ghost commented 5 years ago

In 0.1.x versions, we ware able to use ? operator on respond() method if function return type was Result<_, Box<dyn Error>>.

In version 0.2.0 it looks like digest_auth::error::Error is not convertible to Box<dyn Error> and it started throwing errors.

In 0.1.x versions, we ware able to use `?` operator on `respond()` method if function return type was `Result<_, Box<dyn Error>>`. In version 0.2.0 it looks like `digest_auth::error::Error` is not convertible to `Box<dyn Error>` and it started throwing errors.
Owner

Before, the functions returned failure::Fallible<_>, now they return a custom Error, and I removed failure as a dependency.

Do you think there's something I should add to make it work better?

Before, the functions returned `failure::Fallible<_>`, now they return a custom Error, and I removed `failure` as a dependency. Do you think there's something I should add to make it work better?
Poster

It would be nice to have it compatible with:

fn foo() -> Result<(), Box<dyn Error>> {
   (...)
        let authorization = digest_auth::parse(www_authenticate)?
            .respond(
                &digest_auth::AuthContext::new(
                    &self.login,
                    &self.password,
                    uri.as_str(),
                )
            )?.to_header_string();
   (...)
}

It was super ok for version 0.1.x, now it won't compile with errors as on topic.

Won't that be enough and easy to just implement this trait: https://doc.rust-lang.org/nightly/std/error/trait.Error.html for your custom error? I think you will need to implement just one method - source() that will probably just return None;

It would be nice to have it compatible with: ``` fn foo() -> Result<(), Box<dyn Error>> { (...) let authorization = digest_auth::parse(www_authenticate)? .respond( &digest_auth::AuthContext::new( &self.login, &self.password, uri.as_str(), ) )?.to_header_string(); (...) } ``` It was super ok for version 0.1.x, now it won't compile with errors as on topic. Won't that be enough and easy to just implement this trait: https://doc.rust-lang.org/nightly/std/error/trait.Error.html for your custom error? I think you will need to implement just one method - `source()` that will probably just return `None`;
Owner

yep, I think that's it, I thought it'll be auto-implemented if you have Display and Debug. I'll add a unit test to check for this compatibility

yep, I think that's it, I thought it'll be auto-implemented if you have Display and Debug. I'll add a unit test to check for this compatibility
Poster

If something is Display and Debug it won't necessarily be Error ;) For example IpAddr. I don't think it could be used as error.

If something is `Display` and `Debug` it won't necessarily be `Error` ;) For example `IpAddr`. I don't think it could be used as error.
Owner

of course, it makes sense now.

Please check if version 0.2.1 fixes the problem.

There's some other changes in v0.2, namely AuthContext now uses Cows, but the constructor should be backward compatible. It also implements parsing and display for both headers, so it should be usable server-side too.

of course, it makes sense now. Please check if version 0.2.1 fixes the problem. There's some other changes in v0.2, namely `AuthContext` now uses Cows, but the constructor should be backward compatible. It also implements parsing and display for both headers, so it should be usable server-side too.
Poster

Works like charm

Works like charm
Ghost closed this issue 5 years ago
Sign in to join this conversation.
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: packages/digest_auth_rs#3
Loading…
There is no content yet.