Repository: thrift Updated Branches: refs/heads/master fcb2f5a8f -> 1b20b18ec
Add default message for TApplicationException since some implementations may not set message field Client: go This closes #1335 Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/1b20b18e Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/1b20b18e Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/1b20b18e Branch: refs/heads/master Commit: 1b20b18ec0a4d8eeb7f40566df5ef45a50d697c8 Parents: fcb2f5a Author: damnever <dxc.w...@gmail.com> Authored: Tue Sep 5 13:14:06 2017 +0800 Committer: James E. King, III <jk...@apache.org> Committed: Tue Sep 5 20:00:38 2017 -0700 ---------------------------------------------------------------------- lib/go/thrift/application_exception.go | 16 +++++++++++++++- lib/go/thrift/application_exception_test.go | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/1b20b18e/lib/go/thrift/application_exception.go ---------------------------------------------------------------------- diff --git a/lib/go/thrift/application_exception.go b/lib/go/thrift/application_exception.go index 6655cc5..525bce2 100644 --- a/lib/go/thrift/application_exception.go +++ b/lib/go/thrift/application_exception.go @@ -30,6 +30,17 @@ const ( PROTOCOL_ERROR = 7 ) +var defaultApplicationExceptionMessage = map[int32]string{ + UNKNOWN_APPLICATION_EXCEPTION: "unknown application exception", + UNKNOWN_METHOD: "unknown method", + INVALID_MESSAGE_TYPE_EXCEPTION: "invalid message type", + WRONG_METHOD_NAME: "wrong method name", + BAD_SEQUENCE_ID: "bad sequence ID", + MISSING_RESULT: "missing result", + INTERNAL_ERROR: "unknown internal error", + PROTOCOL_ERROR: "unknown protocol error", +} + // Application level Thrift exception type TApplicationException interface { TException @@ -44,7 +55,10 @@ type tApplicationException struct { } func (e tApplicationException) Error() string { - return e.message + if e.message != "" { + return e.message + } + return defaultApplicationExceptionMessage[e.type_] } func NewTApplicationException(type_ int32, message string) TApplicationException { http://git-wip-us.apache.org/repos/asf/thrift/blob/1b20b18e/lib/go/thrift/application_exception_test.go ---------------------------------------------------------------------- diff --git a/lib/go/thrift/application_exception_test.go b/lib/go/thrift/application_exception_test.go index 7010f86..b2687a6 100644 --- a/lib/go/thrift/application_exception_test.go +++ b/lib/go/thrift/application_exception_test.go @@ -25,7 +25,7 @@ import ( func TestTApplicationException(t *testing.T) { exc := NewTApplicationException(UNKNOWN_APPLICATION_EXCEPTION, "") - if exc.Error() != "" { + if exc.Error() != defaultApplicationExceptionMessage[UNKNOWN_APPLICATION_EXCEPTION] { t.Fatalf("Expected empty string for exception but found '%s'", exc.Error()) } if exc.TypeId() != UNKNOWN_APPLICATION_EXCEPTION {