You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since the generated error is a struct, errors.Is() cannot be used directly. The only way to check errors is to use the more cumbersome errors.As() alternative.
Golang allows errors to implement the interface{ Is(error) bool }, which allows complex errors to be scanned with errors.Is. Something as straightforward as:
Problem
The template for generating errors only implements the
Error() string
interface.Since the generated error is a struct,
errors.Is()
cannot be used directly. The only way to check errors is to use the more cumbersomeerrors.As()
alternative.Proposal
Golang allows errors to implement the
interface{ Is(error) bool }
, which allows complex errors to be scanned witherrors.Is
. Something as straightforward as:Could allow one-line checks like this:
Or even allow for nice switch statements:
References
This feature would be insanely helpful for integration tests. Also it could improve code quality on applications that use the ogen client.
The text was updated successfully, but these errors were encountered: