From: zeripath Date: Tue, 5 May 2020 22:48:24 +0000 (+0100) Subject: api.Context.NotFound(...) should tolerate nil (#11288) (#11306) X-Git-Tag: v1.11.5~9 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=91e6a7f7ea26890f3fc8476d31d5a5a8c80a07b2;p=gitea.git api.Context.NotFound(...) should tolerate nil (#11288) (#11306) There is an unfortunate signature change with the api.Context NotFound function; whereas the normal modules/context/Context NotFound function requires an error or nil, the api.Context variant will panic with an NPE if a nil is provided. This PR will allow api.Context.NotFound to tolerate a being passed a nil. Signed-off-by: Andrew Thornton Co-authored-by: Lauris BH --- diff --git a/modules/context/api.go b/modules/context/api.go index fd9983c52b..4e189ce077 100644 --- a/modules/context/api.go +++ b/modules/context/api.go @@ -212,6 +212,11 @@ func (ctx *APIContext) NotFound(objs ...interface{}) { var message = "Not Found" var errors []string for _, obj := range objs { + // Ignore nil + if obj == nil { + continue + } + if err, ok := obj.(error); ok { errors = append(errors, err.Error()) } else {