-
Notifications
You must be signed in to change notification settings - Fork 87
Collect all error messages for Error.Error() #250
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package mssql | |
| import ( | ||
| "database/sql/driver" | ||
| "fmt" | ||
| "strings" | ||
| ) | ||
|
|
||
| // Error represents an SQL Server error. This | ||
|
|
@@ -24,7 +25,14 @@ type Error struct { | |
| } | ||
|
|
||
| func (e Error) Error() string { | ||
| return "mssql: " + e.Message | ||
| var msg strings.Builder | ||
| for i, err := range e.All { | ||
| if i > 0 { | ||
| msg.WriteByte('\n') | ||
| } | ||
| msg.WriteString(fmt.Sprintf("mssql: %s (%d)", err.Message, err.Number)) | ||
| } | ||
| return msg.String() | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how is this change not affecting any tests? Is there really no coverage of this call? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. There is no tests which would check how the string returned by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. without a test, any behavior is considered correct. I think having a test now is worthwhile because it documents the contract that callers can expect. |
||
|
|
||
| func (e Error) String() string { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might last-to-first ordering be preferable? Similar to how exceptions get printed outer-to-inner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that the natural order is the correct one, eg:
So, it is like error log printed when you run an sql query in your terminal.
But I am not sure and open for any suggestions. The main problem I am trying to solve as stated in the PR description is to make
Error()return enough details to take action.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your example implies there are
Errorobjects without a Number. Where willSee previous errorshow up?