Skip to content

Commit 94e801b

Browse files
author
Damir Vandic
committed
Use github.com/pkg/errors and embed error cause in FormattedError
1 parent c20fbeb commit 94e801b

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package graphql
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
76
"reflect"
87
"strings"
98

109
"github.com/graphql-go/graphql/gqlerrors"
1110
"github.com/graphql-go/graphql/language/ast"
11+
"github.com/pkg/errors"
1212
)
1313

1414
type ExecuteParams struct {

gqlerrors/formatted.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
package gqlerrors
22

33
import (
4-
"errors"
5-
64
"github.com/graphql-go/graphql/language/location"
5+
"github.com/pkg/errors"
76
)
87

98
type FormattedError struct {
109
Message string `json:"message"`
1110
Locations []location.SourceLocation `json:"locations"`
11+
cause error
1212
}
1313

1414
func (g FormattedError) Error() string {
1515
return g.Message
1616
}
1717

18+
func (g FormattedError) Cause() error {
19+
return g.cause
20+
}
21+
1822
func NewFormattedError(message string) FormattedError {
1923
err := errors.New(message)
2024
return FormatError(err)
@@ -38,6 +42,7 @@ func FormatError(err error) FormattedError {
3842
return FormattedError{
3943
Message: err.Error(),
4044
Locations: []location.SourceLocation{},
45+
cause: err,
4146
}
4247
}
4348
}

gqlerrors/located.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package gqlerrors
22

33
import (
4-
"errors"
54
"github.com/graphql-go/graphql/language/ast"
5+
"github.com/pkg/errors"
66
)
77

88
// NewLocatedError creates a graphql.Error with location info

located.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package graphql
22

33
import (
4-
"errors"
54
"github.com/graphql-go/graphql/gqlerrors"
65
"github.com/graphql-go/graphql/language/ast"
6+
"github.com/pkg/errors"
77
)
88

99
func NewLocatedError(err interface{}, nodes []ast.Node) *gqlerrors.Error {

0 commit comments

Comments
 (0)