Skip to content

Commit

Permalink
Add panic handler test, remove redundant "graphql:" prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnStarich committed Sep 14, 2021
1 parent 513af5d commit c756fe8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion errors/panic_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ type DefaultPanicHandler struct{}

// MakePanicError creates a new QueryError from a panic that occurred during execution
func (h *DefaultPanicHandler) MakePanicError(ctx context.Context, value interface{}) *QueryError {
return Errorf("graphql: panic occurred: %v", value)
return Errorf("panic occurred: %v", value)
}
24 changes: 24 additions & 0 deletions errors/panic_handler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package errors

import (
"context"
"testing"
)

func TestDefaultPanicHandler(t *testing.T) {
handler := &DefaultPanicHandler{}
qErr := handler.MakePanicError(context.Background(), "foo")
if qErr == nil {
t.Fatal("Panic error must not be nil")
}
const (
expectedMessage = "panic occurred: foo"
expectedError = "graphql: " + expectedMessage
)
if qErr.Error() != expectedError {
t.Errorf("Unexpected panic error message: %q != %q", qErr.Error(), expectedError)
}
if qErr.Message != expectedMessage {
t.Errorf("Unexpected panic QueryError.Message: %q != %q", qErr.Message, expectedMessage)
}
}

0 comments on commit c756fe8

Please sign in to comment.