Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ErrorWithPos.GetUnderlying to ErrorWithPos.Unwrap #261

Merged
merged 1 commit into from Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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