OpenAPITools / OpenAPITools/openapi-generator

[REQ][Rust Client] Error type should implement std::error:Error

Open
#6,651 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

As recommended by the Rust API Guidelines, custom error types used in a Result<T, E> should implement the std::error::Error and std::fmt::Display traits, which is currently not the case.

https://rust-lang.github.io/api-guidelines/interoperability.html#c-good-err:
An error type is any type E used in a Result<T, E> returned by any public function of your crate. Error types should always implement the std::error::Error trait which is the mechanism by which error handling libraries like error-chain abstract over different types of errors, and which allows the error to be used as the source() of another error. [...]

Describe the solution you'd like

Implementing the corrensponding traits in reqwest\api_mod.mustache would improve error handling when using the generated API.

Describe alternatives you've considered

To solve this for my API client, I implemented the traits myself using a custom template. I would be happy to provide a PR for this, if the change is desired by the community.

Additional context

I am currently using SNAPSHOT version 5.0.0-20200613.071037-272.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting reqwest\api_mod.mustache and the generated Rust client error type. Check how its public Result errors are defined, then verify that the generated error implements std::error::Error and std::fmt::Display; done means generated clients expose both traits.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, tooling
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.