diff options
author | zeripath <art27@cantab.net> | 2020-05-05 19:52:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-05 21:52:13 +0300 |
commit | d9de58beee300b77156057713e3c4d28176d9dc0 (patch) | |
tree | 123b47e996658ee6c1d7e3a5997be2f4e4b49bf6 /modules/context/api.go | |
parent | 0396fcf4b54da7c5ff09908e23a16e96dea9cda4 (diff) | |
download | gitea-d9de58beee300b77156057713e3c4d28176d9dc0.tar.gz gitea-d9de58beee300b77156057713e3c4d28176d9dc0.zip |
api.Context.NotFound(...) should tolerate nil (#11288)
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>
Diffstat (limited to 'modules/context/api.go')
-rw-r--r-- | modules/context/api.go | 5 |
1 files changed, 5 insertions, 0 deletions
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 { |