From 7a41716666991ec029a2b69cf5997843c8140dfd Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@41a61cd8-c433-0410-bb1c-e256eeef9e11> Date: Fri, 14 Dec 2007 20:57:00 +0000 Subject: [PATCH] r1403@opsdev009 (orig r74388): dreiss | 2007-12-14 12:56:04 -0800 Thrift: Fix dangling pointer errors and make messages a bit more uniform. Reviewed By: mcslee Test Plan: Honestly, just built the library. Revert Plan: ok Other Notes: Thanks to Ben Maurer. git-svn-id: http://svn.facebook.com/svnroot/thrift/trunk@720 41a61cd8-c433-0410-bb1c-e256eeef9e11 --- lib/cpp/src/Thrift.h | 14 +++++++------- lib/cpp/src/protocol/TProtocolException.h | 11 +++++++++-- lib/cpp/src/transport/TTransportException.h | 14 ++++++++++++-- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/lib/cpp/src/Thrift.h b/lib/cpp/src/Thrift.h index 0134d48..338dbde 100644 --- a/lib/cpp/src/Thrift.h +++ b/lib/cpp/src/Thrift.h @@ -126,13 +126,13 @@ class TApplicationException : public TException { virtual const char* what() const throw() { if (message_.empty()) { switch (type_) { - case UNKNOWN_METHOD: return "Unknown method"; - case INVALID_MESSAGE_TYPE: return "Invalid message type"; - case WRONG_METHOD_NAME: return "Wrong method name"; - case BAD_SEQUENCE_ID: return "Bad sequence identifier"; - case MISSING_RESULT: return "Missing result"; - - default: return "Default TApplicationException."; + case UNKNOWN : return "TApplicationException: Unknown application exception"; + case UNKNOWN_METHOD : return "TApplicationException: Unknown method"; + case INVALID_MESSAGE_TYPE : return "TApplicationException: Invalid message type"; + case WRONG_METHOD_NAME : return "TApplicationException: Wrong method name"; + case BAD_SEQUENCE_ID : return "TApplicationException: Bad sequence identifier"; + case MISSING_RESULT : return "TApplicationException: Missing result"; + default : return "TApplicationException: (Invalid exception type)"; }; } else { return message_.c_str(); diff --git a/lib/cpp/src/protocol/TProtocolException.h b/lib/cpp/src/protocol/TProtocolException.h index 2d542a0..4429a62 100644 --- a/lib/cpp/src/protocol/TProtocolException.h +++ b/lib/cpp/src/protocol/TProtocolException.h @@ -66,8 +66,15 @@ class TProtocolException : public facebook::thrift::TException { virtual const char* what() const throw() { if (message_.empty()) { - return (std::string("Default Protocol Exception: ") + - boost::lexical_cast(type_)).c_str(); + switch (type_) { + case UNKNOWN : return "TProtocolException: Unknown protocol exception"; + case INVALID_DATA : return "TProtocolException: Invalid data"; + case NEGATIVE_SIZE : return "TProtocolException: Negative size"; + case SIZE_LIMIT : return "TProtocolException: Exceeded size limit"; + case BAD_VERSION : return "TProtocolException: Invalid version"; + case NOT_IMPLEMENTED : return "TProtocolException: Not implemented"; + default : return "TProtocolException: (Invalid exception type)"; + } } else { return message_.c_str(); } diff --git a/lib/cpp/src/transport/TTransportException.h b/lib/cpp/src/transport/TTransportException.h index 9b75826..c21719b 100644 --- a/lib/cpp/src/transport/TTransportException.h +++ b/lib/cpp/src/transport/TTransportException.h @@ -75,8 +75,18 @@ class TTransportException : public facebook::thrift::TException { virtual const char* what() const throw() { if (message_.empty()) { - return (std::string("Default Transport Exception: ") + - boost::lexical_cast(type_)).c_str(); + switch (type_) { + case UNKNOWN : return "TTransportException: Unknown transport exception"; + case NOT_OPEN : return "TTransportException: Transport not open"; + case ALREADY_OPEN : return "TTransportException: Transport already open"; + case TIMED_OUT : return "TTransportException: Timed out"; + case END_OF_FILE : return "TTransportException: End of file"; + case INTERRUPTED : return "TTransportException: Interrupted"; + case BAD_ARGS : return "TTransportException: Invalid arguments"; + case CORRUPTED_DATA : return "TTransportException: Corrupted Data"; + case INTERNAL_ERROR : return "TTransportException: Internal error"; + default : return "TTransportException: (Invalid exception type)"; + } } else { return message_.c_str(); } -- 2.11.4.GIT