]> source.dussan.org Git - gitea.git/commitdiff
api.Context.NotFound(...) should tolerate nil (#11288) (#11306)
authorzeripath <art27@cantab.net>
Tue, 5 May 2020 22:48:24 +0000 (23:48 +0100)
committerGitHub <noreply@github.com>
Tue, 5 May 2020 22:48:24 +0000 (17:48 -0500)
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 <art27@cantab.net>
Co-authored-by: Lauris BH <lauris@nix.lv>
modules/context/api.go

index fd9983c52b5b4ff86fb416dbe1be498103b0b2a7..4e189ce07767b227f9d5fcf386c4d1d32405666b 100644 (file)
@@ -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 {