decoder/Thread: throw C++ exceptions on error

This commit is contained in:
Max Kellermann 2016-09-08 20:26:40 +02:00
parent a9acc9c971
commit 5d9a889190

View File

@ -415,19 +415,16 @@ decoder_run_song(DecoderControl &dc,
if (decoder.error.IsDefined()) { if (decoder.error.IsDefined()) {
/* copy the Error from struct Decoder to /* copy the Error from struct Decoder to
DecoderControl */ DecoderControl */
dc.state = DecoderState::ERROR; throw std::move(decoder.error);
dc.error = std::make_exception_ptr(std::move(decoder.error));
} else if (success) } else if (success)
dc.state = DecoderState::STOP; dc.state = DecoderState::STOP;
else { else {
dc.state = DecoderState::ERROR;
const char *error_uri = song.GetURI(); const char *error_uri = song.GetURI();
const std::string allocated = uri_remove_auth(error_uri); const std::string allocated = uri_remove_auth(error_uri);
if (!allocated.empty()) if (!allocated.empty())
error_uri = allocated.c_str(); error_uri = allocated.c_str();
dc.error = std::make_exception_ptr(FormatRuntimeError("Failed to decode %s", error_uri)); throw FormatRuntimeError("Failed to decode %s", error_uri);
} }
dc.client_cond.signal(); dc.client_cond.signal();
@ -453,10 +450,8 @@ try {
Error error; Error error;
path_buffer = AllocatedPath::FromUTF8(uri_utf8, error); path_buffer = AllocatedPath::FromUTF8(uri_utf8, error);
if (path_buffer.IsNull()) { if (path_buffer.IsNull()) {
dc.state = DecoderState::ERROR;
dc.error = std::make_exception_ptr(std::move(error));
dc.CommandFinishedLocked(); dc.CommandFinishedLocked();
return; throw std::move(error);
} }
path_fs = path_buffer; path_fs = path_buffer;