From adad4ab20356d4c16f2df521b205aae7272c105f Mon Sep 17 00:00:00 2001 From: David Reiss Date: Fri, 14 Dec 2007 20:56:04 +0000 Subject: [PATCH] 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: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665392 13f79535-47bb-0310-9956-ffa450edef68 --- 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 0134d48d..338dbdeb 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 2d542a0d..4429a623 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 9b75826e..c21719b2 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.17.1