Skip to content

Commit

Permalink
Always store the original error in QueryError
Browse files Browse the repository at this point in the history
  • Loading branch information
dvic committed Apr 17, 2018
1 parent 16cc3c6 commit 8ebe5b0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type QueryError struct {
Path []interface{} `json:"path,omitempty"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
Rule string `json:"-"`
ResolverError error `json:"-"`
OriginalError error `json:"-"`
PanicValue interface{} `json:"-"`
}

Expand Down
6 changes: 4 additions & 2 deletions internal/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ func (r *Request) Execute(ctx context.Context, s *resolvable.Schema, op *query.O
}()

if err := ctx.Err(); err != nil {
return nil, []*errors.QueryError{errors.Errorf("%s", err)}
qErr := errors.Errorf("%s", err)
qErr.OriginalError = err
return nil, []*errors.QueryError{qErr}
}

return out.Bytes(), r.Errs
Expand Down Expand Up @@ -210,7 +212,7 @@ func execFieldSelection(ctx context.Context, r *Request, f *fieldToExec, path *p
resolverErr := callOut[1].Interface().(error)
err := errors.Errorf("%s", resolverErr)
err.Path = path.toSlice()
err.ResolverError = resolverErr
err.OriginalError = resolverErr
return err
}
return nil
Expand Down
8 changes: 6 additions & 2 deletions internal/exec/selected/selected.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ func applySelectionSet(r *Request, e *resolvable.Object, sels []query.Selection)
p := packer.ValuePacker{ValueType: reflect.TypeOf("")}
v, err := p.Pack(field.Arguments.MustGet("name").Value(r.Vars))
if err != nil {
r.AddError(errors.Errorf("%s", err))
qErr := errors.Errorf("%s", err)
qErr.OriginalError = err
r.AddError(qErr)
return nil
}

Expand Down Expand Up @@ -126,7 +128,9 @@ func applySelectionSet(r *Request, e *resolvable.Object, sels []query.Selection)
var err error
packedArgs, err = fe.ArgsPacker.Pack(args)
if err != nil {
r.AddError(errors.Errorf("%s", err))
qErr := errors.Errorf("%s", err)
qErr.OriginalError = err
r.AddError(qErr)
return
}
}
Expand Down

0 comments on commit 8ebe5b0

Please sign in to comment.