qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [09/12] qpid-proton git commit: NO-JIRA: Map Go errors to amqp::internal-error
Date Thu, 11 Oct 2018 22:21:41 GMT
NO-JIRA: Map Go errors to amqp::internal-error

Previously using go error type name which is not useful, and often empty.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/84844a95
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/84844a95
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/84844a95

Branch: refs/heads/master
Commit: 84844a95c37d8e6dcdc397b9974769e07980e8ae
Parents: ccaeaa0
Author: Alan Conway <aconway@redhat.com>
Authored: Fri Oct 5 17:05:16 2018 -0400
Committer: Alan Conway <aconway@redhat.com>
Committed: Thu Oct 11 15:14:20 2018 -0400

----------------------------------------------------------------------
 go/src/qpid.apache.org/amqp/error.go      | 11 +++++++----
 go/src/qpid.apache.org/proton/wrappers.go | 17 ++++++-----------
 2 files changed, 13 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/84844a95/go/src/qpid.apache.org/amqp/error.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/amqp/error.go b/go/src/qpid.apache.org/amqp/error.go
index 3a178b2..a8974cb 100644
--- a/go/src/qpid.apache.org/amqp/error.go
+++ b/go/src/qpid.apache.org/amqp/error.go
@@ -24,7 +24,6 @@ import "C"
 
 import (
 	"fmt"
-	"reflect"
 )
 
 // Error is an AMQP error condition. It has a name and a description.
@@ -46,10 +45,14 @@ func Errorf(name, format string, arg ...interface{}) Error {
 	return Error{name, fmt.Sprintf(format, arg...)}
 }
 
-// MakeError makes an AMQP error from a go error using the Go error type as the name
-// and the err.Error() string as the description.
+// MakeError makes an AMQP error from a go error: {Name: InternalError, Description: err.Error()}
+// If err is already an amqp.Error it is returned unchanged.
 func MakeError(err error) Error {
-	return Error{reflect.TypeOf(err).Name(), err.Error()}
+	if amqpErr, ok := err.(Error); ok {
+		return amqpErr
+	} else {
+		return Error{InternalError, err.Error()}
+	}
 }
 
 var (

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/84844a95/go/src/qpid.apache.org/proton/wrappers.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/proton/wrappers.go b/go/src/qpid.apache.org/proton/wrappers.go
index a7b7fb2..42b2a23 100644
--- a/go/src/qpid.apache.org/proton/wrappers.go
+++ b/go/src/qpid.apache.org/proton/wrappers.go
@@ -37,10 +37,10 @@ import "C"
 
 import (
 	"fmt"
-	"qpid.apache.org/amqp"
-	"reflect"
 	"time"
 	"unsafe"
+
+	"qpid.apache.org/amqp"
 )
 
 // TODO aconway 2015-05-05: Documentation for generated types.
@@ -379,17 +379,12 @@ func (c Condition) Error() error {
 	return amqp.Error{Name: c.Name(), Description: c.Description()}
 }
 
-// Set a Go error into a condition.
-// If it is not an amqp.Condition use the error type as name, error string as description.
+// Set a Go error into a condition, converting to an amqp.Error using amqp.MakeError
 func (c Condition) SetError(err error) {
 	if err != nil {
-		if cond, ok := err.(amqp.Error); ok {
-			c.SetName(cond.Name)
-			c.SetDescription(cond.Description)
-		} else {
-			c.SetName(reflect.TypeOf(err).Name())
-			c.SetDescription(err.Error())
-		}
+		cond := amqp.MakeError(err)
+		c.SetName(cond.Name)
+		c.SetDescription(cond.Description)
 	}
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message