Skip to content

Commit

Permalink
show all locations in error string
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed May 14, 2017
1 parent 4ee57b8 commit 56a88e3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions errors/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package errors

import "fmt"
import (
"fmt"
)

type QueryError struct {
Message string `json:"message"`
Expand Down Expand Up @@ -28,11 +30,11 @@ func (err *QueryError) Error() string {
if err == nil {
return "<nil>"
}
if len(err.Locations) > 0 {
loc := err.Locations[0]
return fmt.Sprintf("graphql: %s (line %d, column %d)", err.Message, loc.Line, loc.Column)
str := fmt.Sprintf("graphql: %s", err.Message)
for _, loc := range err.Locations {
str += fmt.Sprintf(" (line %d, column %d)", loc.Line, loc.Column)
}
return fmt.Sprintf("graphql: %s", err.Message)
return str
}

var _ error = &QueryError{}

0 comments on commit 56a88e3

Please sign in to comment.