Skip to content

Commit

Permalink
Merge pull request #147 from ec2-software/unwarp-error-list
Browse files Browse the repository at this point in the history
Allow checking gqlerror.List for wrapped errors with `errors.Is` and `errors.As`
  • Loading branch information
lwc authored Apr 7, 2021
2 parents 6de10c5 + f66f07a commit b0c17ab
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: golang:1.11
- image: golang:1.13
working_directory: /gqlparser
steps:
- checkout
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/vektah/gqlparser/v2

go 1.12
go 1.13

require (
github.com/agnivade/levenshtein v1.0.1
Expand Down
19 changes: 19 additions & 0 deletions gqlerror/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gqlerror

import (
"bytes"
"errors"
"fmt"
"strconv"

Expand Down Expand Up @@ -80,6 +81,24 @@ func (errs List) Error() string {
return buf.String()
}

func (errs List) Is(target error) bool {
for _, err := range errs {
if errors.Is(err, target) {
return true
}
}
return false
}

func (errs List) As(target interface{}) bool {
for _, err := range errs {
if errors.As(err, target) {
return true
}
}
return false
}

func WrapPath(path ast.Path, err error) *Error {
return &Error{
err: err,
Expand Down

0 comments on commit b0c17ab

Please sign in to comment.