Skip to content

Conversation

jegorbunov
Copy link

Sometimes mssql server reports a chain of errors with the last error having a message like: Could not drop constraint. See previous errors.. Since users code will generally print an error by simply using .Error() method to get the details about an underlying error then the method should provide as much detail as possible in my opinion.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.88%. Comparing base (d27f997) to head (03636c0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #250      +/-   ##
==========================================
- Coverage   74.91%   74.88%   -0.03%     
==========================================
  Files          32       32              
  Lines        6457     6463       +6     
==========================================
+ Hits         4837     4840       +3     
- Misses       1332     1334       +2     
- Partials      288      289       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

msg.WriteString(fmt.Sprintf("mssql: %s (%d)", err.Message, err.Number))
}
return msg.String()
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Author

Choose a reason for hiding this comment

The 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 Error() string is formed. Do you think we need them?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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) Error() string {
return "mssql: " + e.Message
var msg strings.Builder
for i, err := range e.All {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ge e.All

might last-to-first ordering be preferable? Similar to how exceptions get printed outer-to-inner

Copy link
Author

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:

mssql: .... actual reason ...
mssql: Failed to drop constraint. See previous error.

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.

Copy link
Collaborator

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 Error objects without a Number. Where will See previous error show up?

Copy link
Collaborator

@shueybubbles shueybubbles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants