summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2016-05-13 12:54:41 +0200
committerMax Kellermann <max@duempel.org>2016-05-13 13:01:39 +0200
commitb7b7c381ee9b8f1058f69a982b280ea6160724e6 (patch)
tree856f07d50802af5093f0e86bcd21f63455bc7036 /src
parent995cd95474971bb14a931f88607b3d00763179f6 (diff)
decoder/Thread: catch exceptions
Allow decoders to throw std::runtime_error.
Diffstat (limited to 'src')
-rw-r--r--src/decoder/DecoderThread.cxx22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/decoder/DecoderThread.cxx b/src/decoder/DecoderThread.cxx
index 4cf79ab68..dfc73960b 100644
--- a/src/decoder/DecoderThread.cxx
+++ b/src/decoder/DecoderThread.cxx
@@ -39,6 +39,7 @@
#include "tag/ApeReplayGain.hxx"
#include "Log.hxx"
+#include <stdexcept>
#include <functional>
#include <memory>
@@ -351,10 +352,29 @@ decoder_run_file(Decoder &decoder, const char *uri_utf8, Path path_fs)
*/
static bool
DecoderUnlockedRunUri(Decoder &decoder, const char *real_uri, Path path_fs)
-{
+try {
return !path_fs.IsNull()
? decoder_run_file(decoder, real_uri, path_fs)
: decoder_run_stream(decoder, real_uri);
+} catch (const std::runtime_error &e) {
+ /* copy the exception to decoder.error */
+
+ if (decoder.error.IsDefined()) {
+ /* decoder.error already set, now we have a second
+ one; only log the second one */
+ LogError(e);
+ return false;
+ }
+
+ const char *error_uri = real_uri;
+ const std::string allocated = uri_remove_auth(error_uri);
+ if (!allocated.empty())
+ error_uri = allocated.c_str();
+
+ decoder.error.Format(decoder_domain,
+ "Failed to decode %s: %s",
+ error_uri, e.what());
+ return false;
}
/**