Skip to content

Commit

Permalink
physic: Change parseError.Error() formatting (google#314)
Browse files Browse the repository at this point in the history
Add option for no original string.
  • Loading branch information
NeuralSpaz authored and maruel committed Nov 7, 2018
1 parent 8508d47 commit 118880d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions conn/physic/units.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,9 @@ func (p *parseError) Error() string {
if p.err == nil {
return "parse error"
}
if p.s == "" {
return "parse error: " + p.err.Error()
}
return "parse error: " + p.err.Error() + ": \"" + p.s + "\""
}

Expand Down
2 changes: 1 addition & 1 deletion conn/physic/units_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ func TestParseError(t *testing.T) {
want string
}{
{"empty", &parseError{s: "", err: nil}, "parse error"},
{"empty", &parseError{s: "", err: errors.New("test")}, "parse error: test: \"" + "\""},
{"empty", &parseError{s: "", err: errors.New("test")}, "parse error: test"},
{"noUnits", noUnits("someunit"), "parse error: no units provided, need: \"someunit\""},
}
for _, tt := range tests {
Expand Down

0 comments on commit 118880d

Please sign in to comment.