oxidecomputer / dropshot

expose REST APIs from a Rust program
Apache License 2.0
843 stars 74 forks source link

[3/n] [dropshot-endpoint] factor out endpoint and parameter validation #1008

Closed sunshowers closed 4 months ago

sunshowers commented 4 months ago

We're going to reuse a lot of this code for server endpoints. Refactor code to prepare for that. I think it's overall a nice improvement :)

For successful generation, there are absolutely no changes in output. (This is a standalone PR, so it's easy to see this.)

In error cases:

  1. Since we encapsulate the different parts of parsing into their own types, there are some minor changes to the situations where we produce errors. Among the fixtures we have, there are a few outputs that change -- I think all for the better.
  2. If the function is valid, but the metadata is not, we pass through the original function without doing any modifications to it. This leads to a much better experience for traits, and a slightly better one for functions.

Also add a little bit of error-handling infrastructure in the form of an ErrorStore. This makes it reasonable to have this kind of nested structure, where each component can determine whether it produced errors. We're going to use this more extensively within the server macro, since that has to maintain separate error contexts per endpoint.

As part of this, do_endpoint and do_channel no longer return Result types -- all errors are handled internally, and instead they return a pair of output and a list of errors. This resolves an inconsistency that I've been bothered by for a bit.

Depends on #1007.

sunshowers commented 4 months ago

(Looks like the tests aren't running because this is a dependent PR not targeting main. Yay for github's terrible support for stacks.)