From 821f77325ce8e060247424bb4bd17a5e3db1abb8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 21 Jul 2018 07:20:59 +0200 Subject: SongFilter: Parse() throws exception on error --- src/command/DatabaseCommands.cxx | 40 +++++++++++++++++++++++++++++----------- src/command/QueueCommands.cxx | 8 ++++++-- 2 files changed, 35 insertions(+), 13 deletions(-) (limited to 'src/command') diff --git a/src/command/DatabaseCommands.cxx b/src/command/DatabaseCommands.cxx index 9ab41958b..1b6e59769 100644 --- a/src/command/DatabaseCommands.cxx +++ b/src/command/DatabaseCommands.cxx @@ -31,6 +31,7 @@ #include "tag/ParseName.hxx" #include "tag/Mask.hxx" #include "util/ConstBuffer.hxx" +#include "util/Exception.hxx" #include "util/StringAPI.hxx" #include "SongFilter.hxx" #include "BulkEdit.hxx" @@ -96,8 +97,11 @@ handle_match(Client &client, Request args, Response &r, bool fold_case) } SongFilter filter; - if (!filter.Parse(args, fold_case)) { - r.Error(ACK_ERROR_ARG, "incorrect arguments"); + try { + filter.Parse(args, fold_case); + } catch (...) { + r.Error(ACK_ERROR_ARG, + GetFullMessage(std::current_exception()).c_str()); return CommandResult::ERROR; } @@ -126,8 +130,11 @@ static CommandResult handle_match_add(Client &client, Request args, Response &r, bool fold_case) { SongFilter filter; - if (!filter.Parse(args, fold_case)) { - r.Error(ACK_ERROR_ARG, "incorrect arguments"); + try { + filter.Parse(args, fold_case); + } catch (...) { + r.Error(ACK_ERROR_ARG, + GetFullMessage(std::current_exception()).c_str()); return CommandResult::ERROR; } @@ -157,8 +164,11 @@ handle_searchaddpl(Client &client, Request args, Response &r) const char *playlist = args.shift(); SongFilter filter; - if (!filter.Parse(args, true)) { - r.Error(ACK_ERROR_ARG, "incorrect arguments"); + try { + filter.Parse(args, true); + } catch (...) { + r.Error(ACK_ERROR_ARG, + GetFullMessage(std::current_exception()).c_str()); return CommandResult::ERROR; } @@ -187,9 +197,14 @@ handle_count(Client &client, Request args, Response &r) } SongFilter filter; - if (!args.empty() && !filter.Parse(args, false)) { - r.Error(ACK_ERROR_ARG, "incorrect arguments"); - return CommandResult::ERROR; + if (!args.empty()) { + try { + filter.Parse(args, false); + } catch (...) { + r.Error(ACK_ERROR_ARG, + GetFullMessage(std::current_exception()).c_str()); + return CommandResult::ERROR; + } } PrintSongCount(r, client.GetPartition(), "", &filter, group); @@ -255,8 +270,11 @@ handle_list(Client &client, Request args, Response &r) if (!args.empty()) { filter.reset(new SongFilter()); - if (!filter->Parse(args, false)) { - r.Error(ACK_ERROR_ARG, "not able to parse args"); + try { + filter->Parse(args, false); + } catch (...) { + r.Error(ACK_ERROR_ARG, + GetFullMessage(std::current_exception()).c_str()); return CommandResult::ERROR; } } diff --git a/src/command/QueueCommands.cxx b/src/command/QueueCommands.cxx index 3457842c7..89dd885f3 100644 --- a/src/command/QueueCommands.cxx +++ b/src/command/QueueCommands.cxx @@ -35,6 +35,7 @@ #include "Instance.hxx" #include "BulkEdit.hxx" #include "util/ConstBuffer.hxx" +#include "util/Exception.hxx" #include "util/StringAPI.hxx" #include "util/NumberParser.hxx" @@ -264,8 +265,11 @@ handle_playlist_match(Client &client, Request args, Response &r, bool fold_case) { SongFilter filter; - if (!filter.Parse(args, fold_case)) { - r.Error(ACK_ERROR_ARG, "incorrect arguments"); + try { + filter.Parse(args, fold_case); + } catch (...) { + r.Error(ACK_ERROR_ARG, + GetFullMessage(std::current_exception()).c_str()); return CommandResult::ERROR; } -- cgit v1.2.3