Make parsing the error code and sql state from the error message more robust.


Project: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/commit/f5d6dfb3
Tree: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/tree/f5d6dfb3
Diff: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/diff/f5d6dfb3

Branch: refs/heads/master
Commit: f5d6dfb3da421af3f966229a06ca96f46fe5353a
Parents: d761d38
Author: Francis Chuang <francis.chu...@gmail.com>
Authored: Tue May 31 20:06:13 2016 +1000
Committer: Julian Hyde <jh...@apache.org>
Committed: Thu Aug 10 18:47:08 2017 -0700

----------------------------------------------------------------------
 errors.go | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/blob/f5d6dfb3/errors.go
----------------------------------------------------------------------
diff --git a/errors.go b/errors.go
index d704375..abef290 100644
--- a/errors.go
+++ b/errors.go
@@ -55,10 +55,22 @@ func (r ResponseError) Name() string {
 // errorResponseToReponseError converts an error protocol buffer response
 // to a native golang error.
 func errorResponseToResponseError(message *message.ErrorResponse) 
ResponseError {
-       re := regexp.MustCompile(`java.sql.SQLException: ERROR (\d+) \((\d+)\)`)
+
+       var (
+               errorCode int
+               sqlState  string
+       )
+
+       re := regexp.MustCompile(`ERROR (\d+) \((\d+)\)`)
        codes := re.FindStringSubmatch(message.ErrorMessage)
-       errorCode, _ := strconv.Atoi(codes[1])
-       sqlState := codes[2]
+
+       if len(codes) > 1 {
+               errorCode, _ = strconv.Atoi(codes[1])
+       }
+
+       if len(codes) > 2 {
+               sqlState = codes[2]
+       }
 
        err := ResponseError{
                Exceptions:   message.Exceptions,

Reply via email to