Skip to content

Commit

Permalink
Change ErrorWithPos.GetUnderlying to ErrorWithPos.Unwrap (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
bufdev authored and jhump committed Aug 2, 2019
1 parent 8771ced commit b1090fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion desc/protoparse/error_reporting_test.go
Expand Up @@ -193,7 +193,7 @@ func TestErrorReporting(t *testing.T) {
testutil.Eq(t, tc.expectedErrs[j], reported[j].Error(), "case #%d: parse error[%d] have %q; instead got %q", i+1, j, tc.expectedErrs[j], reported[j].Error())
split := strings.SplitN(tc.expectedErrs[j], ":", 4)
testutil.Eq(t, 4, len(split), "case #%d: expected %q [%d] to contain at least 4 elements split by :", i+1, tc.expectedErrs[j], j)
testutil.Eq(t, split[3], " "+reported[j].GetUnderlying().Error(), "case #%d: parse error underlying[%d] have %q; instead got %q", i+1, j, split[3], reported[j].GetUnderlying().Error())
testutil.Eq(t, split[3], " "+reported[j].Unwrap().Error(), "case #%d: parse error underlying[%d] have %q; instead got %q", i+1, j, split[3], reported[j].Unwrap().Error())
}

count = 0
Expand Down
9 changes: 5 additions & 4 deletions desc/protoparse/errors.go
Expand Up @@ -60,10 +60,11 @@ func (h *errorHandler) getError() error {
// about the location in the file that caused the error.
//
// The value of Error() will contain both the SourcePos and Underlying error.
// The value of Unwrap() will only be the Underlying error.
type ErrorWithPos interface {
error
GetPosition() SourcePos
GetUnderlying() error
Unwrap() error
}

// ErrorWithSourcePos is an error about a proto source file that includes
Expand Down Expand Up @@ -93,9 +94,9 @@ func (e ErrorWithSourcePos) GetPosition() SourcePos {
return *e.Pos
}

// GetUnderlying implements the ErrorWithPos interface, supplying the
// underlying error. This error will not include location information.
func (e ErrorWithSourcePos) GetUnderlying() error {
// Unwrap implements the ErrorWithPos interface, supplying the underlying
// error. This error will not include location information.
func (e ErrorWithSourcePos) Unwrap() error {
return e.Underlying
}

Expand Down

0 comments on commit b1090fc

Please sign in to comment.