Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions terror/terror.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"strconv"

"github.com/modern-go/reflect2"
"github.com/pingcap/errors"
"github.com/pingcap/parser/mysql"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -213,10 +214,16 @@ func (e *Error) Location() (file string, line int) {

// Error implements error interface.
func (e *Error) Error() string {
if reflect2.IsNil(e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why e == nil is not enough? *Error is a concrete type unlike interface{}.

Copy link
Author

Choose a reason for hiding this comment

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

you are right, e == nil is better.

return "<nil>"
}
return fmt.Sprintf("[%s:%d]%s", e.class, e.code, e.getMsg())
}

func (e *Error) getMsg() string {
if reflect2.IsNil(e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

(ditto)

return "<nil>"
}
if len(e.args) > 0 {
return fmt.Sprintf(e.message, e.args...)
}
Expand Down