test/*: catch and print all exceptions

This commit is contained in:
Max Kellermann 2018-07-17 21:56:43 +02:00
parent edb44a536a
commit d6529d8c60
24 changed files with 116 additions and 122 deletions

View File

@ -18,7 +18,6 @@
*/ */
#include "config.h" #include "config.h"
#include "Log.hxx"
#include "DetachedSong.hxx" #include "DetachedSong.hxx"
#include "SongSave.hxx" #include "SongSave.hxx"
#include "decoder/DecoderList.hxx" #include "decoder/DecoderList.hxx"
@ -27,6 +26,7 @@
#include "fs/io/StdioOutputStream.hxx" #include "fs/io/StdioOutputStream.hxx"
#include "fs/io/BufferedOutputStream.hxx" #include "fs/io/BufferedOutputStream.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include "util/PrintException.hxx"
#include <stdexcept> #include <stdexcept>
@ -93,7 +93,7 @@ try {
decoder_plugin_deinit_all(); decoder_plugin_deinit_all();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -32,8 +32,8 @@
#include "tag/Config.hxx" #include "tag/Config.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "event/Thread.hxx" #include "event/Thread.hxx"
#include "Log.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
#include "util/PrintException.hxx"
#include <stdexcept> #include <stdexcept>
#include <iostream> #include <iostream>
@ -152,7 +152,7 @@ try {
db->Visit(selection, DumpDirectory, DumpSong, DumpPlaylist); db->Visit(selection, DumpDirectory, DumpSong, DumpPlaylist);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -21,10 +21,10 @@
#include "tag/ApeLoader.hxx" #include "tag/ApeLoader.hxx"
#include "thread/Mutex.hxx" #include "thread/Mutex.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "Log.hxx"
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "input/LocalOpen.hxx" #include "input/LocalOpen.hxx"
#include "util/StringView.hxx" #include "util/StringView.hxx"
#include "util/PrintException.hxx"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -70,7 +70,7 @@ try {
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -19,7 +19,7 @@
#include "config.h" #include "config.h"
#include "fs/io/FileOutputStream.hxx" #include "fs/io/FileOutputStream.hxx"
#include "Log.hxx" #include "util/PrintException.hxx"
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
@ -49,7 +49,7 @@ Copy(OutputStream &dest, int src)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ try {
if (argc != 2) { if (argc != 2) {
fprintf(stderr, "Usage: WriteFile PATH\n"); fprintf(stderr, "Usage: WriteFile PATH\n");
return EXIT_FAILURE; return EXIT_FAILURE;
@ -57,17 +57,15 @@ main(int argc, char **argv)
const Path path = Path::FromFS(argv[1]); const Path path = Path::FromFS(argv[1]);
try { FileOutputStream fos(path);
FileOutputStream fos(path);
if (!Copy(fos, STDIN_FILENO)) if (!Copy(fos, STDIN_FILENO))
return EXIT_FAILURE;
fos.Commit();
return EXIT_SUCCESS;
} catch (const std::exception &e) {
LogError(e);
return EXIT_FAILURE; return EXIT_FAILURE;
}
fos.Commit();
return EXIT_SUCCESS;
} catch (...) {
PrintException(std::current_exception());
return EXIT_FAILURE;
} }

View File

@ -32,7 +32,7 @@
#include "fs/io/BufferedOutputStream.hxx" #include "fs/io/BufferedOutputStream.hxx"
#include "fs/io/StdioOutputStream.hxx" #include "fs/io/StdioOutputStream.hxx"
#include "thread/Cond.hxx" #include "thread/Cond.hxx"
#include "Log.hxx" #include "util/PrintException.hxx"
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
@ -125,7 +125,7 @@ try {
config_global_finish(); config_global_finish();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -26,7 +26,7 @@
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "input/LocalOpen.hxx" #include "input/LocalOpen.hxx"
#include "Log.hxx" #include "util/PrintException.hxx"
#include <id3tag.h> #include <id3tag.h>
@ -95,7 +95,7 @@ try {
DumpReplayGainInfo(replay_gain); DumpReplayGainInfo(replay_gain);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -23,7 +23,7 @@
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "input/TextInputStream.hxx" #include "input/TextInputStream.hxx"
#include "config/Global.hxx" #include "config/Global.hxx"
#include "Log.hxx" #include "util/PrintException.hxx"
#ifdef ENABLE_ARCHIVE #ifdef ENABLE_ARCHIVE
#include "archive/ArchiveList.hxx" #include "archive/ArchiveList.hxx"
@ -96,7 +96,7 @@ try {
auto is = InputStream::OpenReady(argv[1], mutex); auto is = InputStream::OpenReady(argv[1], mutex);
return dump_input_stream(std::move(is)); return dump_input_stream(std::move(is));
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -20,7 +20,8 @@
#include "config.h" #include "config.h"
#include "config/Global.hxx" #include "config/Global.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "Log.hxx" #include "fs/Path.hxx"
#include "util/PrintException.hxx"
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
@ -55,7 +56,7 @@ try {
config_global_finish(); config_global_finish();
return ret; return ret;
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -26,7 +26,7 @@
#include "Main.hxx" #include "Main.hxx"
#include "event/Loop.hxx" #include "event/Loop.hxx"
#include "config/Block.hxx" #include "config/Block.hxx"
#include "Log.hxx" #include "util/PrintException.hxx"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
@ -76,7 +76,7 @@ try {
printf("%d\n", volume); printf("%d\n", volume);
return 0; return 0;
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -27,9 +27,9 @@
#include "tag/Generic.hxx" #include "tag/Generic.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "AudioFormat.hxx" #include "AudioFormat.hxx"
#include "Log.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
#include "util/StringBuffer.hxx" #include "util/StringBuffer.hxx"
#include "util/PrintException.hxx"
#include <stdexcept> #include <stdexcept>
@ -108,8 +108,8 @@ try {
bool success; bool success;
try { try {
success = plugin->ScanFile(path, h); success = plugin->ScanFile(path, h);
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
success = false; success = false;
} }
@ -134,7 +134,7 @@ try {
} }
return 0; return 0;
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -29,7 +29,7 @@
#include "pcm/PcmConvert.hxx" #include "pcm/PcmConvert.hxx"
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
#include "util/StaticFifoBuffer.hxx" #include "util/StaticFifoBuffer.hxx"
#include "Log.hxx" #include "util/PrintException.hxx"
#include <assert.h> #include <assert.h>
#include <stddef.h> #include <stddef.h>
@ -98,7 +98,7 @@ try {
state.Close(); state.Close();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -29,6 +29,7 @@
#include "AudioFormat.hxx" #include "AudioFormat.hxx"
#include "util/OptionDef.hxx" #include "util/OptionDef.hxx"
#include "util/OptionParser.hxx" #include "util/OptionParser.hxx"
#include "util/PrintException.hxx"
#include "Log.hxx" #include "Log.hxx"
#include "LogBackend.hxx" #include "LogBackend.hxx"
@ -136,7 +137,7 @@ try {
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -26,7 +26,7 @@
#include "AudioParser.hxx" #include "AudioParser.hxx"
#include "config/Block.hxx" #include "config/Block.hxx"
#include "fs/io/StdioOutputStream.hxx" #include "fs/io/StdioOutputStream.hxx"
#include "Log.hxx" #include "util/PrintException.hxx"
#include <memory> #include <memory>
@ -36,7 +36,7 @@
#include <unistd.h> #include <unistd.h>
int main(int argc, char **argv) int main(int argc, char **argv)
{ try {
const char *encoder_name; const char *encoder_name;
static char buffer[32768]; static char buffer[32768];
@ -64,35 +64,33 @@ int main(int argc, char **argv)
ConfigBlock block; ConfigBlock block;
block.AddBlockParam("quality", "5.0", -1); block.AddBlockParam("quality", "5.0", -1);
try { std::unique_ptr<PreparedEncoder> p_encoder(encoder_init(*plugin, block));
std::unique_ptr<PreparedEncoder> p_encoder(encoder_init(*plugin, block));
/* open the encoder */ /* open the encoder */
AudioFormat audio_format(44100, SampleFormat::S16, 2); AudioFormat audio_format(44100, SampleFormat::S16, 2);
if (argc > 2) if (argc > 2)
audio_format = ParseAudioFormat(argv[2], false); audio_format = ParseAudioFormat(argv[2], false);
std::unique_ptr<Encoder> encoder(p_encoder->Open(audio_format)); std::unique_ptr<Encoder> encoder(p_encoder->Open(audio_format));
StdioOutputStream os(stdout); StdioOutputStream os(stdout);
EncoderToOutputStream(os, *encoder);
/* do it */
ssize_t nbytes;
while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) {
encoder->Write(buffer, nbytes);
EncoderToOutputStream(os, *encoder); EncoderToOutputStream(os, *encoder);
/* do it */
ssize_t nbytes;
while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) {
encoder->Write(buffer, nbytes);
EncoderToOutputStream(os, *encoder);
}
encoder->End();
EncoderToOutputStream(os, *encoder);
return EXIT_SUCCESS;
} catch (const std::exception &e) {
LogError(e);
return EXIT_FAILURE;
} }
encoder->End();
EncoderToOutputStream(os, *encoder);
return EXIT_SUCCESS;
} catch (...) {
PrintException(std::current_exception());
return EXIT_FAILURE;
} }

View File

@ -31,8 +31,7 @@
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
#include "util/StringBuffer.hxx" #include "util/StringBuffer.hxx"
#include "util/RuntimeError.hxx" #include "util/RuntimeError.hxx"
#include "system/FatalError.hxx" #include "util/PrintException.hxx"
#include "Log.hxx"
#include <memory> #include <memory>
#include <stdexcept> #include <stdexcept>
@ -122,7 +121,7 @@ try {
config_global_finish(); config_global_finish();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -21,7 +21,7 @@
#include "fs/io/GunzipReader.hxx" #include "fs/io/GunzipReader.hxx"
#include "fs/io/FileReader.hxx" #include "fs/io/FileReader.hxx"
#include "fs/io/StdioOutputStream.hxx" #include "fs/io/StdioOutputStream.hxx"
#include "Log.hxx" #include "util/PrintException.hxx"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -57,7 +57,7 @@ CopyGunzip(FILE *_dest, Path src_path)
int int
main(int argc, gcc_unused char **argv) main(int argc, gcc_unused char **argv)
{ try {
if (argc != 2) { if (argc != 2) {
fprintf(stderr, "Usage: run_gunzip PATH\n"); fprintf(stderr, "Usage: run_gunzip PATH\n");
return EXIT_FAILURE; return EXIT_FAILURE;
@ -65,11 +65,9 @@ main(int argc, gcc_unused char **argv)
Path path = Path::FromFS(argv[1]); Path path = Path::FromFS(argv[1]);
try { CopyGunzip(stdout, path);
CopyGunzip(stdout, path); return EXIT_SUCCESS;
return EXIT_SUCCESS; } catch (...) {
} catch (const std::exception &e) { PrintException(std::current_exception());
LogError(e); return EXIT_FAILURE;
return EXIT_FAILURE;
}
} }

View File

@ -21,7 +21,7 @@
#include "fs/io/GzipOutputStream.hxx" #include "fs/io/GzipOutputStream.hxx"
#include "fs/io/StdioOutputStream.hxx" #include "fs/io/StdioOutputStream.hxx"
#include "system/Error.hxx" #include "system/Error.hxx"
#include "Log.hxx" #include "util/PrintException.hxx"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -61,17 +61,15 @@ CopyGzip(FILE *_dest, int src)
int int
main(int argc, gcc_unused char **argv) main(int argc, gcc_unused char **argv)
{ try {
if (argc != 1) { if (argc != 1) {
fprintf(stderr, "Usage: run_gzip\n"); fprintf(stderr, "Usage: run_gzip\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
try { CopyGzip(stdout, STDIN_FILENO);
CopyGzip(stdout, STDIN_FILENO); return EXIT_SUCCESS;
return EXIT_SUCCESS; } catch (...) {
} catch (const std::exception &e) { PrintException(std::current_exception());
LogError(e); return EXIT_FAILURE;
return EXIT_FAILURE;
}
} }

View File

@ -37,6 +37,7 @@
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
#include "util/OptionDef.hxx" #include "util/OptionDef.hxx"
#include "util/OptionParser.hxx" #include "util/OptionParser.hxx"
#include "util/PrintException.hxx"
#ifdef ENABLE_ARCHIVE #ifdef ENABLE_ARCHIVE
#include "archive/ArchiveList.hxx" #include "archive/ArchiveList.hxx"
@ -241,7 +242,7 @@ try {
Mutex mutex; Mutex mutex;
auto is = InputStream::OpenReady(c.uri, mutex); auto is = InputStream::OpenReady(c.uri, mutex);
return dump_input_stream(is.get()); return dump_input_stream(is.get());
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -25,7 +25,7 @@
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "event/Loop.hxx" #include "event/Loop.hxx"
#include "ShutdownHandler.hxx" #include "ShutdownHandler.hxx"
#include "Log.hxx" #include "util/PrintException.hxx"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -93,7 +93,7 @@ try {
loop.Run(); loop.Run();
neighbor.Close(); neighbor.Close();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -27,7 +27,7 @@
#include "AudioCompress/compress.h" #include "AudioCompress/compress.h"
#include "AudioParser.hxx" #include "AudioParser.hxx"
#include "AudioFormat.hxx" #include "AudioFormat.hxx"
#include "Log.hxx" #include "util/PrintException.hxx"
#include <stdexcept> #include <stdexcept>
@ -63,7 +63,7 @@ try {
Compressor_delete(compressor); Compressor_delete(compressor);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -32,7 +32,7 @@
#include "util/StringBuffer.hxx" #include "util/StringBuffer.hxx"
#include "util/RuntimeError.hxx" #include "util/RuntimeError.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
#include "Log.hxx" #include "util/PrintException.hxx"
#include <memory> #include <memory>
@ -146,7 +146,7 @@ try {
config_global_finish(); config_global_finish();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -18,13 +18,13 @@
*/ */
#include "config.h" #include "config.h"
#include "Log.hxx"
#include "event/Thread.hxx" #include "event/Thread.hxx"
#include "storage/Registry.hxx" #include "storage/Registry.hxx"
#include "storage/StorageInterface.hxx" #include "storage/StorageInterface.hxx"
#include "storage/FileInfo.hxx" #include "storage/FileInfo.hxx"
#include "net/Init.hxx" #include "net/Init.hxx"
#include "util/ChronoUtil.hxx" #include "util/ChronoUtil.hxx"
#include "util/PrintException.hxx"
#include <memory> #include <memory>
#include <stdexcept> #include <stdexcept>
@ -124,7 +124,7 @@ try {
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -28,7 +28,7 @@
#include "AudioParser.hxx" #include "AudioParser.hxx"
#include "AudioFormat.hxx" #include "AudioFormat.hxx"
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
#include "Log.hxx" #include "util/PrintException.hxx"
#include <stdio.h> #include <stdio.h>
#include <stddef.h> #include <stddef.h>
@ -59,7 +59,7 @@ try {
} }
pv.Close(); pv.Close();
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -27,7 +27,7 @@
#include "fs/io/StdioOutputStream.hxx" #include "fs/io/StdioOutputStream.hxx"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "tag/Builder.hxx" #include "tag/Builder.hxx"
#include "Log.hxx" #include "util/PrintException.hxx"
#include <memory> #include <memory>
@ -95,7 +95,7 @@ try {
EncoderToOutputStream(os, *encoder); EncoderToOutputStream(os, *encoder);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -27,7 +27,7 @@
#include "archive/ArchiveFile.hxx" #include "archive/ArchiveFile.hxx"
#include "archive/ArchiveVisitor.hxx" #include "archive/ArchiveVisitor.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "Log.hxx" #include "util/PrintException.hxx"
#include <stdexcept> #include <stdexcept>
@ -95,7 +95,7 @@ try {
file->Visit(visitor); file->Visit(visitor);
return result; return result;
} catch (const std::exception &e) { } catch (...) {
LogError(e); PrintException(std::current_exception());
return EXIT_FAILURE; return EXIT_FAILURE;
} }