Commit 8f93c364 authored by Max Kellermann's avatar Max Kellermann

command/AllCommands: catch and report std::exception

parent 3092e5a8
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "config.h" #include "config.h"
#include "AllCommands.hxx" #include "AllCommands.hxx"
#include "CommandError.hxx"
#include "Request.hxx" #include "Request.hxx"
#include "QueueCommands.hxx" #include "QueueCommands.hxx"
#include "TagCommands.hxx" #include "TagCommands.hxx"
...@@ -411,9 +412,14 @@ command_process(Client &client, unsigned num, char *line) ...@@ -411,9 +412,14 @@ command_process(Client &client, unsigned num, char *line)
command_checked_lookup(r, client.GetPermission(), command_checked_lookup(r, client.GetPermission(),
cmd_name, args); cmd_name, args);
CommandResult ret = cmd try {
? cmd->handler(client, args, r) CommandResult ret = cmd
: CommandResult::ERROR; ? cmd->handler(client, args, r)
: CommandResult::ERROR;
return ret; return ret;
} catch (const std::exception &e) {
PrintError(r, e);
return CommandResult::ERROR;
}
} }
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx" #include "Log.hxx"
#include <system_error>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
...@@ -155,3 +157,17 @@ print_error(Response &r, const Error &error) ...@@ -155,3 +157,17 @@ print_error(Response &r, const Error &error)
r.Error(ToAck(error), error.GetMessage()); r.Error(ToAck(error), error.GetMessage());
return CommandResult::ERROR; return CommandResult::ERROR;
} }
void
PrintError(Response &r, const std::exception &e)
{
LogError(e);
try {
throw e;
} catch (const std::system_error &) {
r.Error(ACK_ERROR_SYSTEM, e.what());
} catch (...) {
r.Error(ACK_ERROR_UNKNOWN, e.what());
}
}
...@@ -23,6 +23,10 @@ ...@@ -23,6 +23,10 @@
#include "CommandResult.hxx" #include "CommandResult.hxx"
#include "PlaylistError.hxx" #include "PlaylistError.hxx"
namespace std {
class exception;
}
class Response; class Response;
class Error; class Error;
...@@ -35,4 +39,7 @@ print_playlist_result(Response &r, PlaylistResult result); ...@@ -35,4 +39,7 @@ print_playlist_result(Response &r, PlaylistResult result);
CommandResult CommandResult
print_error(Response &r, const Error &error); print_error(Response &r, const Error &error);
void
PrintError(Response &r, const std::exception &e);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment