From 888df00d42ebd51f97db9c19a480df2edb496ab7 Mon Sep 17 00:00:00 2001 From: Steve Coffman Date: Fri, 20 Dec 2024 10:22:42 -0500 Subject: [PATCH] If the graphql.AddError err arg is nil, early return Signed-off-by: Steve Coffman --- graphql/context_response.go | 3 +++ graphql/error.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/graphql/context_response.go b/graphql/context_response.go index e0f3285fb05..340a4048cec 100644 --- a/graphql/context_response.go +++ b/graphql/context_response.go @@ -51,6 +51,9 @@ func AddErrorf(ctx context.Context, format string, args ...any) { // AddError sends an error to the client, first passing it through the error presenter. func AddError(ctx context.Context, err error) { + if err == nil { + return + } c := getResponseContext(ctx) presentedError := c.errorPresenter(ctx, ErrorOnPath(ctx, err)) diff --git a/graphql/error.go b/graphql/error.go index f816bef6b8e..bfcecd9a8d8 100644 --- a/graphql/error.go +++ b/graphql/error.go @@ -10,6 +10,9 @@ import ( type ErrorPresenterFunc func(ctx context.Context, err error) *gqlerror.Error func DefaultErrorPresenter(ctx context.Context, err error) *gqlerror.Error { + if err == nil { + return nil + } var gqlErr *gqlerror.Error if errors.As(err, &gqlErr) { return gqlErr