decoder/Thread: catch exceptions
Allow decoders to throw std::runtime_error.
This commit is contained in:
@@ -39,6 +39,7 @@
|
|||||||
#include "tag/ApeReplayGain.hxx"
|
#include "tag/ApeReplayGain.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@@ -351,10 +352,29 @@ decoder_run_file(Decoder &decoder, const char *uri_utf8, Path path_fs)
|
|||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
DecoderUnlockedRunUri(Decoder &decoder, const char *real_uri, Path path_fs)
|
DecoderUnlockedRunUri(Decoder &decoder, const char *real_uri, Path path_fs)
|
||||||
{
|
try {
|
||||||
return !path_fs.IsNull()
|
return !path_fs.IsNull()
|
||||||
? decoder_run_file(decoder, real_uri, path_fs)
|
? decoder_run_file(decoder, real_uri, path_fs)
|
||||||
: decoder_run_stream(decoder, real_uri);
|
: 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user