Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve MockService ergonomics for sending error responses #2810

Conversation

jvff
Copy link
Contributor

@jvff jvff commented Sep 29, 2021

Motivation

While working on the tests in #2801, I stumbled onto an issue with the MockService. Unfortunately, the Error generic type parameter had a constraint where it needed to std::error::Error, and that's not actually necessary. This caused some issues when I was trying to respond to requests with errors.

Solution

I removed the constraint, but I also used the opportunity to improve the ergonomics of responding with errors in general. This PR includes changes to:

  1. Remove the Error: std::error::Error constraint;
  2. Automatic conversion of a provided SourceError type into a TargetError type, so the caller doesn't have to call .into();
  3. Add a documentation example for responding with an error, that also serves as a simple test case.

Review

Anyone can review this, but since this blocks #2801 and @teor2345 is already reviewing that PR, I tagged them directly.

Reviewer Checklist

  • Code implements Specs and Designs
  • Tests for Expected Behaviour
  • Tests for Errors

Follow Up Work

The generic `Error` type parameter doesn't have to implement the
standard `Error` trait, so having that constraint only unnecessarily
limits the types that can be used as an error for the service.
Make the usage a little more ergonomic by not having to write manual
error type conversions.
Show an example that responds to a call to the service with an error.
@jvff jvff requested review from teor2345 and a team September 29, 2021 22:00
@zfnd-bot zfnd-bot bot assigned jvff Sep 29, 2021
Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for fixing this up.

I'm pretty sure our CI runs doctests, so I'm just going to merge this.

@teor2345 teor2345 enabled auto-merge (squash) September 30, 2021 02:12
@teor2345 teor2345 merged commit 175ac99 into ZcashFoundation:main Sep 30, 2021
@jvff jvff deleted the improve-mock-service-error-response-ergonomics branch September 30, 2021 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants