Skip to content

Commit

Permalink
Fixing panic for oracle error messages
Browse files Browse the repository at this point in the history
Fixes xo#105.
  • Loading branch information
Kenneth Shaw committed Dec 19, 2019
1 parent 68e0874 commit a2978c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions drivers/oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

// DRIVER: godror
_ "github.com/godror/godror"
"golang.org/x/xerrors"

"github.com/xo/dburl"
"github.com/xo/usql/drivers"
Expand Down Expand Up @@ -49,15 +50,23 @@ func init() {
return err
},
Err: func(err error) (string, string) {
code, msg := "", err.Error()
if e := xerrors.Unwrap(err); e != nil {
err = e
}

code, msg := "", err.Error()
if e, ok := err.(interface {
Code() int
}); ok {
code = fmt.Sprintf("ORA-%05d", e.Code())
}
if e, ok := err.(interface {
Message() string
}); ok {
msg = e.Message()
}

if i := strings.LastIndex(msg, "ORA-"); i != -1 {
if i := strings.LastIndex(msg, "ORA-"); msg == "" && i != -1 {
msg = msg[i:]
if j := strings.Index(msg, ":"); j != -1 {
msg = msg[j+1:]
Expand All @@ -70,6 +79,9 @@ func init() {
return code, strings.TrimSpace(msg)
},
IsPasswordErr: func(err error) bool {
if e := xerrors.Unwrap(err); e != nil {
err = e
}
if e, ok := err.(interface {
Code() int
}); ok {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ require (
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 // indirect
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
golang.org/x/sys v0.0.0-20191218084908-4a24b4065292 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
google.golang.org/appengine v1.6.5 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/jcmturner/gokrb5.v6 v6.1.1 // indirect
Expand Down

0 comments on commit a2978c0

Please sign in to comment.