Skip to content

Commit

Permalink
api.Context.NotFound(...) should tolerate nil (#11288) (#11306)
Browse files Browse the repository at this point in the history
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 <[email protected]>

Co-authored-by: Lauris BH <[email protected]>
  • Loading branch information
zeripath and lafriks authored May 5, 2020
1 parent ff7eaa1 commit 91e6a7f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions modules/context/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 91e6a7f

Please sign in to comment.