danielgtaylor / huma

Huma REST/HTTP API Framework for Golang with OpenAPI 3.1
https://huma.rocks/
MIT License
1.89k stars 138 forks source link

returning nil for both the output struct and the error from a handler panics #544

Closed guneyizol closed 4 weeks ago

guneyizol commented 1 month ago

Hello ✋

Below code panics because both the response and the error are returned as nil. Is this a feature or a bug? IMHO handling this case gracefully would be better for UX.

Thanks 🙏

mux := http.NewServeMux()

api := humago.New(mux, huma.DefaultConfig("My API", "1.0.0"))

huma.Register(
    api,
    huma.Operation{
        Method: http.MethodPost,
        Path:   "/",
    },
    func(ctx context.Context, input *Input) (*Output, error) {
        return nil, nil
    }
)
danielgtaylor commented 4 weeks ago

@guneyizol thanks for reporting! I've thrown up a quick PR to fix this.