input/InputStream: migrate from class Error to C++ exceptions

This commit is contained in:
Max Kellermann
2016-09-09 18:47:42 +02:00
parent 597e59f10d
commit 8c744efd56
64 changed files with 440 additions and 473 deletions

View File

@@ -34,11 +34,12 @@
#include "util/MimeType.hxx"
#include "util/UriUtil.hxx"
#include "util/StringUtil.hxx"
#include "util/Error.hxx"
#include "util/Macros.hxx"
#include "config/ConfigGlobal.hxx"
#include "config/Block.hxx"
#include <stdexcept>
#include <assert.h>
#include <string.h>
@@ -193,7 +194,10 @@ playlist_list_open_stream_mime2(InputStreamPtr &&is, const char *mime)
StringArrayContainsCase(plugin->mime_types, mime)) {
/* rewind the stream, so each plugin gets a
fresh start */
is->Rewind(IgnoreError());
try {
is->Rewind();
} catch (const std::runtime_error &) {
}
auto playlist = playlist_plugin_open_stream(plugin,
std::move(is));
@@ -234,7 +238,10 @@ playlist_list_open_stream_suffix(InputStreamPtr &&is, const char *suffix)
StringArrayContainsCase(plugin->suffixes, suffix)) {
/* rewind the stream, so each plugin gets a
fresh start */
is->Rewind(IgnoreError());
try {
is->Rewind();
} catch (const std::runtime_error &) {
}
auto playlist = playlist_plugin_open_stream(plugin,
std::move(is));

View File

@@ -23,7 +23,6 @@
#include "../MemorySongEnumerator.hxx"
#include "tag/TagBuilder.hxx"
#include "util/ASCII.hxx"
#include "util/Error.hxx"
#include "util/StringView.hxx"
#include "lib/expat/ExpatParser.hxx"
#include "Log.hxx"
@@ -152,12 +151,7 @@ asx_open_stream(InputStreamPtr &&is)
ExpatParser expat(&parser);
expat.SetElementHandler(asx_start_element, asx_end_element);
expat.SetCharacterDataHandler(asx_char_data);
Error error;
if (!expat.Parse(*is, error)) {
LogError(error);
return nullptr;
}
expat.Parse(*is);
}
parser.songs.reverse();

View File

@@ -23,7 +23,6 @@
#include "../MemorySongEnumerator.hxx"
#include "tag/TagBuilder.hxx"
#include "util/ASCII.hxx"
#include "util/Error.hxx"
#include "util/StringView.hxx"
#include "lib/expat/ExpatParser.hxx"
#include "Log.hxx"
@@ -150,12 +149,7 @@ rss_open_stream(InputStreamPtr &&is)
ExpatParser expat(&parser);
expat.SetElementHandler(rss_start_element, rss_end_element);
expat.SetCharacterDataHandler(rss_char_data);
Error error;
if (!expat.Parse(*is, error)) {
LogError(error);
return nullptr;
}
expat.Parse(*is);
}
parser.songs.reverse();

View File

@@ -26,7 +26,6 @@
#include "tag/TagBuilder.hxx"
#include "util/StringCompare.hxx"
#include "util/Alloc.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "util/ScopeExit.hxx"
#include "Log.hxx"
@@ -231,29 +230,20 @@ static int
soundcloud_parse_json(const char *url, yajl_handle hand,
Mutex &mutex, Cond &cond)
try {
Error error;
auto input_stream = InputStream::OpenReady(url, mutex, cond);
const ScopeLock protect(mutex);
yajl_status stat;
int done = 0;
bool done = false;
while (!done) {
char buffer[4096];
unsigned char *ubuffer = (unsigned char *)buffer;
const size_t nbytes =
input_stream->Read(buffer, sizeof(buffer), error);
if (nbytes == 0) {
if (error.IsDefined())
LogError(error);
if (input_stream->IsEOF()) {
done = true;
} else {
return -1;
}
}
input_stream->Read(buffer, sizeof(buffer));
if (nbytes == 0)
done = true;
if (done) {
stat = yajl_complete_parse(hand);

View File

@@ -24,7 +24,6 @@
#include "DetachedSong.hxx"
#include "input/InputStream.hxx"
#include "tag/TagBuilder.hxx"
#include "util/Error.hxx"
#include "util/StringView.hxx"
#include "lib/expat/ExpatParser.hxx"
#include "Log.hxx"
@@ -197,12 +196,7 @@ xspf_open_stream(InputStreamPtr &&is)
ExpatParser expat(&parser);
expat.SetElementHandler(xspf_start_element, xspf_end_element);
expat.SetCharacterDataHandler(xspf_char_data);
Error error;
if (!expat.Parse(*is, error)) {
LogError(error);
return nullptr;
}
expat.Parse(*is);
}
parser.songs.reverse();