Skip to content

Collect all error messages for Error.Error()#250

Merged
dlevy-msft-sql merged 2 commits into
microsoft:mainfrom
dlapko:make-error-great-again-to-upstream
May 13, 2026
Merged

Collect all error messages for Error.Error()#250
dlevy-msft-sql merged 2 commits into
microsoft:mainfrom
dlapko:make-error-great-again-to-upstream

Conversation

@jegorbunov
Copy link
Copy Markdown

@jegorbunov jegorbunov commented Apr 4, 2025

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.

CHANGELOG

BREAKING CHANGE:

Before this patch an Error() method would return a message like:

mssql: message

After this commit it returns:

mssql: message (error number)

And even:

mssql: message 1 (error number 1)
mssql: message 2 (error number 2)
...

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.60%. Comparing base (abddba8) to head (9602fa0).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main     #250       +/-   ##
===========================================
+ Coverage   80.56%   96.60%   +16.04%     
===========================================
  Files          35       92       +57     
  Lines        6910    74361    +67451     
===========================================
+ Hits         5567    71840    +66273     
- Misses       1070     2186     +1116     
- Partials      273      335       +62     
Flag Coverage Δ
unittests 96.54% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
error.go 100.00% <100.00%> (ø)

... and 59 files with indirect coverage changes

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

Comment thread error.go
Comment thread error.go Outdated
Copy link
Copy Markdown
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.

🕐

@jegorbunov jegorbunov force-pushed the make-error-great-again-to-upstream branch from 03636c0 to 138412a Compare March 31, 2026 12:14
@jegorbunov jegorbunov requested a review from shueybubbles March 31, 2026 12:14
@jegorbunov
Copy link
Copy Markdown
Author

@shueybubbles, can you have another look?

I've fixed the comments: now tests do check how error messages are formed in a more detailed way.

Comment thread error.go
Comment thread error_test.go Outdated
Comment thread error.go Outdated
@dlevy-msft-sql
Copy link
Copy Markdown

@jegorbunov friendly nudge — two items from the last review still open:

  1. Nil-All regression (blocking): Error() returns "" when All is empty. token.go:165 constructs Error{Message: "Request failed but didn't provide reason"} without populating All, and external callers can do the same. Simplest fix:

    func (e Error) Error() string {
        if len(e.All) == 0 {
            return "mssql: " + e.Message
        }
        // ... existing All loop ...
    }

    That also lets you drop the err.All = []Error{err} workaround in TestError_Methods.

  2. Single-error format change (design): For a single error the output goes from "mssql: msg" to "mssql: msg (num)". That is a breaking change for anyone matching error strings. Two reasonable resolutions:

    • Keep the old format for the 1-error case and only multi-line when len(All) > 1, or
    • Keep the new format but call it out in the PR body / CHANGELOG so the breaking change is explicit.

Happy to push the fix to your branch (maintainer_can_modify is enabled) if you would rather not iterate further — just let me know. Otherwise, take your time.

Before this commit all Error-related tests would not specify
the expected behaviour of Error.Error() method. This commit
adds such expectations so that it is visible when these
expectations change.
@jegorbunov jegorbunov force-pushed the make-error-great-again-to-upstream branch from 138412a to 3528ecc Compare May 13, 2026 10:19
Also error numbers were added to the Error() returned message.

BREAKING CHANGE:

Before this commit an error Error() returned text would look like:

`mssql: message`

After this commit:

`mssql: message (error number)`

And even:

```
mssql: message 1 (error number 1)
mssql: message 2 (error number 2)
...
```
@jegorbunov jegorbunov force-pushed the make-error-great-again-to-upstream branch from 3528ecc to 9602fa0 Compare May 13, 2026 10:22
@jegorbunov
Copy link
Copy Markdown
Author

@jegorbunov friendly nudge — two items from the last review still open:

  1. Nil-All regression (blocking): Error() returns "" when All is empty. token.go:165 constructs Error{Message: "Request failed but didn't provide reason"} without populating All, and external callers can do the same. Simplest fix:

    func (e Error) Error() string {
        if len(e.All) == 0 {
            return "mssql: " + e.Message
        }
        // ... existing All loop ...
    }

    That also lets you drop the err.All = []Error{err} workaround in TestError_Methods.

  2. Single-error format change (design): For a single error the output goes from "mssql: msg" to "mssql: msg (num)". That is a breaking change for anyone matching error strings. Two reasonable resolutions:

    • Keep the old format for the 1-error case and only multi-line when len(All) > 1, or
    • Keep the new format but call it out in the PR body / CHANGELOG so the breaking change is explicit.

Happy to push the fix to your branch (maintainer_can_modify is enabled) if you would rather not iterate further — just let me know. Otherwise, take your time.

Thanks for the wait.

I've fixed the first problem and added a CHANGELOG section to the PR/commit message as for the second problem. I believe that having an error number in the message is helpful enough for the change.

@jegorbunov jegorbunov requested a review from dlevy-msft-sql May 13, 2026 10:27
@dlevy-msft-sql dlevy-msft-sql merged commit 4b3b062 into microsoft:main May 13, 2026
8 checks passed
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.

4 participants