diff options
author | Wim <wim@42.be> | 2022-04-01 00:23:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-01 00:23:19 +0200 |
commit | c6716e030c02f316b887c1d3ee4b443aa3ab6afd (patch) | |
tree | 470461fe2d29662e7a69834ed21fce30beed65ab /vendor/github.com/graph-gophers/graphql-go/errors | |
parent | 4ab72acec656dafd304f88359b509b1f27c06604 (diff) | |
download | matterbridge-msglm-c6716e030c02f316b887c1d3ee4b443aa3ab6afd.tar.gz matterbridge-msglm-c6716e030c02f316b887c1d3ee4b443aa3ab6afd.tar.bz2 matterbridge-msglm-c6716e030c02f316b887c1d3ee4b443aa3ab6afd.zip |
Update dependencies (#1784)
Diffstat (limited to 'vendor/github.com/graph-gophers/graphql-go/errors')
-rw-r--r-- | vendor/github.com/graph-gophers/graphql-go/errors/errors.go | 59 | ||||
-rw-r--r-- | vendor/github.com/graph-gophers/graphql-go/errors/panic_handler.go | 18 |
2 files changed, 77 insertions, 0 deletions
diff --git a/vendor/github.com/graph-gophers/graphql-go/errors/errors.go b/vendor/github.com/graph-gophers/graphql-go/errors/errors.go new file mode 100644 index 00000000..0f9340b1 --- /dev/null +++ b/vendor/github.com/graph-gophers/graphql-go/errors/errors.go @@ -0,0 +1,59 @@ +package errors + +import ( + "fmt" +) + +type QueryError struct { + Err error `json:"-"` // Err holds underlying if available + Message string `json:"message"` + Locations []Location `json:"locations,omitempty"` + Path []interface{} `json:"path,omitempty"` + Rule string `json:"-"` + ResolverError error `json:"-"` + Extensions map[string]interface{} `json:"extensions,omitempty"` +} + +type Location struct { + Line int `json:"line"` + Column int `json:"column"` +} + +func (a Location) Before(b Location) bool { + return a.Line < b.Line || (a.Line == b.Line && a.Column < b.Column) +} + +func Errorf(format string, a ...interface{}) *QueryError { + // similar to fmt.Errorf, Errorf will wrap the last argument if it is an instance of error + var err error + if n := len(a); n > 0 { + if v, ok := a[n-1].(error); ok { + err = v + } + } + + return &QueryError{ + Err: err, + Message: fmt.Sprintf(format, a...), + } +} + +func (err *QueryError) Error() string { + if err == nil { + return "<nil>" + } + str := fmt.Sprintf("graphql: %s", err.Message) + for _, loc := range err.Locations { + str += fmt.Sprintf(" (line %d, column %d)", loc.Line, loc.Column) + } + return str +} + +func (err *QueryError) Unwrap() error { + if err == nil { + return nil + } + return err.Err +} + +var _ error = &QueryError{} diff --git a/vendor/github.com/graph-gophers/graphql-go/errors/panic_handler.go b/vendor/github.com/graph-gophers/graphql-go/errors/panic_handler.go new file mode 100644 index 00000000..5446c2a9 --- /dev/null +++ b/vendor/github.com/graph-gophers/graphql-go/errors/panic_handler.go @@ -0,0 +1,18 @@ +package errors + +import ( + "context" +) + +// PanicHandler is the interface used to create custom panic errors that occur during query execution +type PanicHandler interface { + MakePanicError(ctx context.Context, value interface{}) *QueryError +} + +// DefaultPanicHandler is the default PanicHandler +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("panic occurred: %v", value) +} |