summaryrefslogtreecommitdiff
path: root/src/command/AllCommands.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-12-16 11:34:26 +0100
committerMax Kellermann <max@duempel.org>2015-12-16 11:34:26 +0100
commit51168169e73528d388b39b826afe1df3370bd10a (patch)
treef0fcdd175e57a03365b3d3522dd9f50a69f75d0d /src/command/AllCommands.cxx
parentd256a0e98f587c0af714c74038ff75903c0903fe (diff)
util/Tokenizer: use std::runtime_error on syntax error
Diffstat (limited to 'src/command/AllCommands.cxx')
-rw-r--r--src/command/AllCommands.cxx48
1 files changed, 23 insertions, 25 deletions
diff --git a/src/command/AllCommands.cxx b/src/command/AllCommands.cxx
index 9dd1b0a94..8cc8f40c5 100644
--- a/src/command/AllCommands.cxx
+++ b/src/command/AllCommands.cxx
@@ -361,7 +361,7 @@ command_checked_lookup(Response &r, unsigned permission,
CommandResult
command_process(Client &client, unsigned num, char *line)
-{
+try {
Response r(client, num);
Error error;
@@ -371,13 +371,17 @@ command_process(Client &client, unsigned num, char *line)
Tokenizer tokenizer(line);
- const char *const cmd_name = tokenizer.NextWord(error);
- if (cmd_name == nullptr) {
- if (tokenizer.IsEnd())
- r.FormatError(ACK_ERROR_UNKNOWN, "No command given");
- else
- r.Error(ACK_ERROR_UNKNOWN, error.GetMessage());
-
+ const char *cmd_name;
+ try {
+ cmd_name = tokenizer.NextWord();
+ if (cmd_name == nullptr) {
+ r.Error(ACK_ERROR_UNKNOWN, "No command given");
+ /* this client does not speak the MPD
+ protocol; kick the connection */
+ return CommandResult::FINISH;
+ }
+ } catch (const std::exception &e) {
+ r.Error(ACK_ERROR_UNKNOWN, e.what());
/* this client does not speak the MPD protocol; kick
the connection */
return CommandResult::FINISH;
@@ -394,14 +398,9 @@ command_process(Client &client, unsigned num, char *line)
return CommandResult::ERROR;
}
- char *a = tokenizer.NextParam(error);
- if (a == nullptr) {
- if (tokenizer.IsEnd())
- break;
-
- r.Error(ACK_ERROR_UNKNOWN, error.GetMessage());
- return CommandResult::ERROR;
- }
+ char *a = tokenizer.NextParam();
+ if (a == nullptr)
+ break;
argv[args.size++] = a;
}
@@ -412,14 +411,13 @@ command_process(Client &client, unsigned num, char *line)
command_checked_lookup(r, client.GetPermission(),
cmd_name, args);
- try {
- CommandResult ret = cmd
- ? cmd->handler(client, args, r)
- : CommandResult::ERROR;
+ CommandResult ret = cmd
+ ? cmd->handler(client, args, r)
+ : CommandResult::ERROR;
- return ret;
- } catch (const std::exception &e) {
- PrintError(r, e);
- return CommandResult::ERROR;
- }
+ return ret;
+} catch (const std::exception &e) {
+ Response r(client, num);
+ PrintError(r, e);
+ return CommandResult::ERROR;
}