ogen
ogen copied to clipboard
gen: s.h.NewError is not used when parameters fail to decode
What version of ogen are you using?
$ go list -m github.com/ogen-go/ogen
github.com/ogen-go/ogen v1.14.0
Can this issue be reproduced with the latest version?
Yes
What did you do?
The following is needed
- NewErrors method in the handler from the convenient errors feature
- A parameter that is decoded
To reproduce the problem, decoding the parameter needs to fail. E.g. the format is a UUID, but the length is wrong.
What did you expect to see?
An ogenerrors.DecodeParamsError pointer value is passed to NewError to be handled like other errors.
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w); encodeErr != nil {
defer recordError("DecodeParams", err)
}
What did you see instead?
An ogenerrors.DecodeParamsError pointer value is passed to the default error handler:
s.cfg.ErrorHandler(ctx, w, r, err)
For constrast, the security section of the oas_handlers_gen for an operation does use NewError.
If I'm understanding the code correctly, that particular error handling is generated by this part of the handlers template.
It also seems like decoding the request will have similar issues.