Skip to content

Commit

Permalink
Protocol generator: record last error message received
Browse files Browse the repository at this point in the history
Store this as a string (as well as the error code) so that we can report it to
the user, for example in test failure messages.
  • Loading branch information
qris committed Aug 4, 2017
1 parent efcb9ad commit 01e238b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
8 changes: 4 additions & 4 deletions lib/backupstore/StoreTestUtils.h
Expand Up @@ -93,17 +93,17 @@ bool delete_account();
{ \
TEST_EQUAL_LINE(BackupProtocolError::error, subtype, \
"command returned error: " << \
BackupProtocolError::GetMessage(subtype)); \
(protocol).GetLastErrorMessage()); \
if (subtype != BackupProtocolError::error) \
{ \
or_statements; \
} \
} \
else \
{ \
TEST_FAIL_WITH_MESSAGE("command did not return an error, but a " \
"response of type " << type << ", subtype " << subtype << \
" instead"); \
TEST_FAIL_WITH_MESSAGE("command did not return an error, " \
"but " << (protocol).GetLastErrorMessage() << " " \
"instead (" << type << "/" << subtype << ")"); \
or_statements; \
} \
}
Expand Down
19 changes: 12 additions & 7 deletions lib/server/makeprotocol.pl.in
Expand Up @@ -582,12 +582,14 @@ public:
virtual std::auto_ptr<IOStream> ReceiveStream() = 0;
bool GetLastError(int &rTypeOut, int &rSubTypeOut);
int GetLastErrorType() { return mLastErrorSubType; }
const std::string& GetLastErrorMessage() { return mLastErrorMessage; }

protected:
void SetLastError(int Type, int SubType)
void SetLastError(int Type, int SubType, const std::string& Message)
{
mLastErrorType = Type;
mLastErrorSubType = SubType;
mLastErrorMessage = Message;
}
std::string mPreviousCommand;
std::string mPreviousReply;
Expand All @@ -596,6 +598,7 @@ private:
$client_server_base_class(const $client_server_base_class &rToCopy); /* do not call */
int mLastErrorType;
int mLastErrorSubType;
std::string mLastErrorMessage;
};

class $replyable_base_class : public virtual $client_server_base_class
Expand All @@ -621,7 +624,8 @@ __E
print CPP <<__E;
$client_server_base_class\::$client_server_base_class()
: mLastErrorType(Protocol::NoError),
mLastErrorSubType(Protocol::NoError)
mLastErrorSubType(Protocol::NoError),
mLastErrorMessage("no messages received")
{ }

$client_server_base_class\::~$client_server_base_class()
Expand Down Expand Up @@ -684,7 +688,7 @@ void $callable_base_class\::CheckReply(const std::string& requestCommandName,
if(rReply.GetType() == expectedType)
{
// Correct response, do nothing
SetLastError(Protocol::NoError, Protocol::NoError);
SetLastError(Protocol::NoError, Protocol::NoError, "no error");
}
else
{
Expand All @@ -693,7 +697,7 @@ void $callable_base_class\::CheckReply(const std::string& requestCommandName,

if(rReply.IsError(type, subType))
{
SetLastError(type, subType);
SetLastError(type, subType, (($error_class&)rReply).GetMessage());
THROW_EXCEPTION_MESSAGE(ConnectionException,
Protocol_UnexpectedReply,
requestCommandName << " command failed: "
Expand All @@ -702,12 +706,13 @@ void $callable_base_class\::CheckReply(const std::string& requestCommandName,
}
else
{
SetLastError(Protocol::UnknownError, Protocol::UnknownError);
SetLastError(Protocol::UnknownError, Protocol::UnknownError,
rReply.ToString());
THROW_EXCEPTION_MESSAGE(ConnectionException,
Protocol_UnexpectedReply,
requestCommandName << " command failed: "
"received unexpected response type " <<
rReply.GetType());
"received unexpected response " <<
rReply.ToString());
}
}

Expand Down

0 comments on commit 01e238b

Please sign in to comment.