lib/fmt/RuntimeError: new library

Replacing FormatRuntimeError().
This commit is contained in:
Max Kellermann 2022-11-28 21:58:21 +01:00
parent 45b13fc2a6
commit fa58db798b
105 changed files with 551 additions and 502 deletions

View File

@ -27,6 +27,7 @@
#include "config/Net.hxx" #include "config/Net.hxx"
#include "lib/fmt/ExceptionFormatter.hxx" #include "lib/fmt/ExceptionFormatter.hxx"
#include "lib/fmt/PathFormatter.hxx" #include "lib/fmt/PathFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "net/AllocatedSocketAddress.hxx" #include "net/AllocatedSocketAddress.hxx"
#include "net/UniqueSocketDescriptor.hxx" #include "net/UniqueSocketDescriptor.hxx"
#include "net/SocketUtil.hxx" #include "net/SocketUtil.hxx"
@ -35,7 +36,6 @@
#include "fs/StandardDirectory.hxx" #include "fs/StandardDirectory.hxx"
#include "fs/XDG.hxx" #include "fs/XDG.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/RuntimeError.hxx"
#include <sys/stat.h> #include <sys/stat.h>
@ -129,8 +129,8 @@ listen_global_init(const ConfigData &config, ClientListener &listener)
ServerSocketAddGeneric(listener, param.value.c_str(), ServerSocketAddGeneric(listener, param.value.c_str(),
port); port);
} catch (...) { } catch (...) {
std::throw_with_nested(FormatRuntimeError("Failed to listen on %s (line %i)", std::throw_with_nested(FmtRuntimeError("Failed to listen on {} (line {})",
param.value.c_str(), param.value,
param.line)); param.line));
} }
} }
@ -146,7 +146,8 @@ listen_global_init(const ConfigData &config, ClientListener &listener)
try { try {
listener.AddPort(port); listener.AddPort(port);
} catch (...) { } catch (...) {
std::throw_with_nested(FormatRuntimeError("Failed to listen on *:%d: ", port)); std::throw_with_nested(FmtRuntimeError("Failed to listen on *:{}",
port));
} }
} }

View File

@ -22,13 +22,13 @@
#include "LogBackend.hxx" #include "LogBackend.hxx"
#include "Log.hxx" #include "Log.hxx"
#include "lib/fmt/PathFormatter.hxx" #include "lib/fmt/PathFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "config/Param.hxx" #include "config/Param.hxx"
#include "config/Data.hxx" #include "config/Data.hxx"
#include "config/Option.hxx" #include "config/Option.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/RuntimeError.hxx"
#include "util/StringAPI.hxx" #include "util/StringAPI.hxx"
#include "lib/fmt/SystemError.hxx" #include "lib/fmt/SystemError.hxx"
@ -79,9 +79,8 @@ log_init_file(int line)
out_fd = open_log_file(); out_fd = open_log_file();
if (out_fd < 0) { if (out_fd < 0) {
#ifdef _WIN32 #ifdef _WIN32
const std::string out_path_utf8 = out_path.ToUTF8(); throw FmtRuntimeError("failed to open log file \"{}\" (config line {})",
throw FormatRuntimeError("failed to open log file \"%s\" (config line %d)", out_path, line);
out_path_utf8.c_str(), line);
#else #else
throw FmtErrno("failed to open log file \"{}\" (config line {})", throw FmtErrno("failed to open log file \"{}\" (config line {})",
out_path, line); out_path, line);
@ -109,7 +108,7 @@ parse_log_level(const char *value)
else if (StringIsEqual(value, "error")) else if (StringIsEqual(value, "error"))
return LogLevel::ERROR; return LogLevel::ERROR;
else else
throw FormatRuntimeError("unknown log level \"%s\"", value); throw FmtRuntimeError("unknown log level \"{}\"", value);
} }
#endif #endif

View File

@ -59,7 +59,6 @@
#include "config/Domain.hxx" #include "config/Domain.hxx"
#include "config/Parser.hxx" #include "config/Parser.hxx"
#include "config/PartitionConfig.hxx" #include "config/PartitionConfig.hxx"
#include "util/RuntimeError.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
#ifdef ENABLE_DAEMON #ifdef ENABLE_DAEMON

View File

@ -22,11 +22,11 @@
#include "config/Param.hxx" #include "config/Param.hxx"
#include "config/Data.hxx" #include "config/Data.hxx"
#include "config/Option.hxx" #include "config/Option.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "net/AddressInfo.hxx" #include "net/AddressInfo.hxx"
#include "net/Resolver.hxx" #include "net/Resolver.hxx"
#include "net/ToString.hxx" #include "net/ToString.hxx"
#include "util/IterableSplitString.hxx" #include "util/IterableSplitString.hxx"
#include "util/RuntimeError.hxx"
#include "util/StringSplit.hxx" #include "util/StringSplit.hxx"
#include <cassert> #include <cassert>
@ -68,8 +68,7 @@ ParsePermission(std::string_view s)
if (s == i->name) if (s == i->name)
return i->value; return i->value;
throw FormatRuntimeError("unknown permission \"%.*s\"", throw FmtRuntimeError("unknown permission \"{}\"", s);
int(s.size()), s.data());
} }
static unsigned static unsigned
@ -103,7 +102,7 @@ initPermissions(const ConfigData &config)
const auto [password, permissions] = const auto [password, permissions] =
Split(value, PERMISSION_PASSWORD_CHAR); Split(value, PERMISSION_PASSWORD_CHAR);
if (permissions.data() == nullptr) if (permissions.data() == nullptr)
throw FormatRuntimeError("\"%c\" not found in password string", throw FmtRuntimeError("\"{}\" not found in password string",
PERMISSION_PASSWORD_CHAR); PERMISSION_PASSWORD_CHAR);
permission_passwords.emplace(password, permission_passwords.emplace(password,

View File

@ -19,11 +19,11 @@
#include "PlaylistDatabase.hxx" #include "PlaylistDatabase.hxx"
#include "db/PlaylistVector.hxx" #include "db/PlaylistVector.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "io/LineReader.hxx" #include "io/LineReader.hxx"
#include "io/BufferedOutputStream.hxx" #include "io/BufferedOutputStream.hxx"
#include "time/ChronoUtil.hxx" #include "time/ChronoUtil.hxx"
#include "util/StringStrip.hxx" #include "util/StringStrip.hxx"
#include "util/RuntimeError.hxx"
#include <fmt/format.h> #include <fmt/format.h>
@ -55,8 +55,7 @@ playlist_metadata_load(LineReader &file, PlaylistVector &pv, const char *name)
std::strcmp(line, "playlist_end") != 0) { std::strcmp(line, "playlist_end") != 0) {
colon = std::strchr(line, ':'); colon = std::strchr(line, ':');
if (colon == nullptr || colon == line) if (colon == nullptr || colon == line)
throw FormatRuntimeError("unknown line in db: %s", throw FmtRuntimeError("unknown line in db: {}", line);
line);
*colon++ = 0; *colon++ = 0;
value = StripLeft(colon); value = StripLeft(colon);
@ -64,8 +63,7 @@ playlist_metadata_load(LineReader &file, PlaylistVector &pv, const char *name)
if (std::strcmp(line, "mtime") == 0) if (std::strcmp(line, "mtime") == 0)
pm.mtime = std::chrono::system_clock::from_time_t(strtol(value, nullptr, 10)); pm.mtime = std::chrono::system_clock::from_time_t(strtol(value, nullptr, 10));
else else
throw FormatRuntimeError("unknown line in db: %s", throw FmtRuntimeError("unknown line in db: {}", line);
line);
} }
pv.UpdateOrInsert(std::move(pm)); pv.UpdateOrInsert(std::move(pm));

View File

@ -23,6 +23,7 @@
#include "song/DetachedSong.hxx" #include "song/DetachedSong.hxx"
#include "TagSave.hxx" #include "TagSave.hxx"
#include "lib/fmt/AudioFormatFormatter.hxx" #include "lib/fmt/AudioFormatFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "io/LineReader.hxx" #include "io/LineReader.hxx"
#include "io/BufferedOutputStream.hxx" #include "io/BufferedOutputStream.hxx"
#include "tag/ParseName.hxx" #include "tag/ParseName.hxx"
@ -32,7 +33,6 @@
#include "util/StringAPI.hxx" #include "util/StringAPI.hxx"
#include "util/StringBuffer.hxx" #include "util/StringBuffer.hxx"
#include "util/StringStrip.hxx" #include "util/StringStrip.hxx"
#include "util/RuntimeError.hxx"
#include "util/NumberParser.hxx" #include "util/NumberParser.hxx"
#include <stdlib.h> #include <stdlib.h>
@ -97,9 +97,8 @@ song_load(LineReader &file, const char *uri,
while ((line = file.ReadLine()) != nullptr && while ((line = file.ReadLine()) != nullptr &&
!StringIsEqual(line, SONG_END)) { !StringIsEqual(line, SONG_END)) {
char *colon = std::strchr(line, ':'); char *colon = std::strchr(line, ':');
if (colon == nullptr || colon == line) { if (colon == nullptr || colon == line)
throw FormatRuntimeError("unknown line in db: %s", line); throw FmtRuntimeError("unknown line in db: {}", line);
}
*colon++ = 0; *colon++ = 0;
const char *value = StripLeft(colon); const char *value = StripLeft(colon);
@ -134,7 +133,7 @@ song_load(LineReader &file, const char *uri,
song.SetStartTime(SongTime::FromMS(start_ms)); song.SetStartTime(SongTime::FromMS(start_ms));
song.SetEndTime(SongTime::FromMS(end_ms)); song.SetEndTime(SongTime::FromMS(end_ms));
} else { } else {
throw FormatRuntimeError("unknown line in db: %s", line); throw FmtRuntimeError("unknown line in db: {}", line);
} }
} }

View File

@ -27,7 +27,8 @@
#include "../ArchiveVisitor.hxx" #include "../ArchiveVisitor.hxx"
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/PathFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
#include "util/UTF8.hxx" #include "util/UTF8.hxx"
@ -46,8 +47,8 @@ struct Iso9660 {
explicit Iso9660(Path path) explicit Iso9660(Path path)
:iso(iso9660_open(path.c_str())) { :iso(iso9660_open(path.c_str())) {
if (iso == nullptr) if (iso == nullptr)
throw FormatRuntimeError("Failed to open ISO9660 file %s", throw FmtRuntimeError("Failed to open ISO9660 file {}",
path.c_str()); path);
} }
~Iso9660() noexcept { ~Iso9660() noexcept {
@ -238,7 +239,7 @@ Iso9660ArchiveFile::OpenStream(const char *pathname,
{ {
auto statbuf = iso9660_ifs_stat_translate(iso->iso, pathname); auto statbuf = iso9660_ifs_stat_translate(iso->iso, pathname);
if (statbuf == nullptr) if (statbuf == nullptr)
throw FormatRuntimeError("not found in the ISO file: %s", throw FmtRuntimeError("not found in the ISO file: {}",
pathname); pathname);
const lsn_t lsn = statbuf->lsn; const lsn_t lsn = statbuf->lsn;

View File

@ -26,25 +26,24 @@
#include "../ArchiveFile.hxx" #include "../ArchiveFile.hxx"
#include "../ArchiveVisitor.hxx" #include "../ArchiveVisitor.hxx"
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "lib/fmt/PathFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "lib/fmt/SystemError.hxx" #include "lib/fmt/SystemError.hxx"
#include "util/RuntimeError.hxx"
#include "util/UTF8.hxx" #include "util/UTF8.hxx"
#include <zzip/zzip.h> #include <zzip/zzip.h>
#include <utility> #include <utility>
#include <cinttypes> /* for PRIoffset (PRIu64) */
struct ZzipDir { struct ZzipDir {
ZZIP_DIR *const dir; ZZIP_DIR *const dir;
explicit ZzipDir(Path path) explicit ZzipDir(Path path)
:dir(zzip_dir_open(path.c_str(), nullptr)) { :dir(zzip_dir_open(path.c_str(), nullptr)) {
if (dir == nullptr) if (dir == nullptr)
throw FormatRuntimeError("Failed to open ZIP file %s", throw FmtRuntimeError("Failed to open ZIP file {}",
path.c_str()); path);
} }
~ZzipDir() noexcept { ~ZzipDir() noexcept {
@ -140,7 +139,7 @@ ZzipArchiveFile::OpenStream(const char *pathname,
pathname); pathname);
default: default:
throw FormatRuntimeError("Failed to open '%s' in ZIP file: %s", throw FmtRuntimeError("Failed to open '{}' in ZIP file: {}",
pathname, pathname,
zzip_strerror(error)); zzip_strerror(error));
} }
@ -161,8 +160,7 @@ ZzipInputStream::Read(std::unique_lock<Mutex> &, void *ptr, size_t read_size)
throw std::runtime_error("zzip_file_read() has failed"); throw std::runtime_error("zzip_file_read() has failed");
if (nbytes == 0 && !IsEOF()) if (nbytes == 0 && !IsEOF())
throw FormatRuntimeError("Unexpected end of file %s" throw FmtRuntimeError("Unexpected end of file {} at {} of {}",
" at %" PRIoffset " of %" PRIoffset,
GetURI(), GetOffset(), GetSize()); GetURI(), GetOffset(), GetSize());
offset = zzip_tell(file); offset = zzip_tell(file);

View File

@ -19,7 +19,7 @@
#include "OptionParser.hxx" #include "OptionParser.hxx"
#include "OptionDef.hxx" #include "OptionDef.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
static const char * static const char *
@ -37,7 +37,7 @@ OptionParser::CheckShiftValue(const char *s, const OptionDef &option)
return nullptr; return nullptr;
if (args.empty()) if (args.empty())
throw FormatRuntimeError("Value expected after %s", s); throw FmtRuntimeError("Value expected after {}", s);
return Shift(args); return Shift(args);
} }
@ -78,7 +78,7 @@ OptionParser::IdentifyOption(const char *s)
} }
} }
throw FormatRuntimeError("Unknown option: %s", s); throw FmtRuntimeError("Unknown option: {}", s);
} }
OptionParser::Result OptionParser::Result

View File

@ -2,6 +2,9 @@ cmdline = static_library(
'cmdline', 'cmdline',
'OptionParser.cxx', 'OptionParser.cxx',
include_directories: inc, include_directories: inc,
dependencies: [
fmt_dep,
],
) )
cmdline_dep = declare_dependency( cmdline_dep = declare_dependency(

View File

@ -21,15 +21,15 @@
#include "Parser.hxx" #include "Parser.hxx"
#include "Path.hxx" #include "Path.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include <stdlib.h> #include <stdlib.h>
void void
BlockParam::ThrowWithNested() const BlockParam::ThrowWithNested() const
{ {
std::throw_with_nested(FormatRuntimeError("Error in setting \"%s\" on line %i", std::throw_with_nested(FmtRuntimeError("Error in setting \"{}\" on line {}",
name.c_str(), line)); name, line));
} }
int int
@ -39,7 +39,7 @@ BlockParam::GetIntValue() const
char *endptr; char *endptr;
long value2 = strtol(s, &endptr, 0); long value2 = strtol(s, &endptr, 0);
if (endptr == s || *endptr != 0) if (endptr == s || *endptr != 0)
throw FormatRuntimeError("Not a valid number in line %i", line); throw FmtRuntimeError("Not a valid number in line {}", line);
return value2; return value2;
} }
@ -147,6 +147,6 @@ ConfigBlock::GetBlockValue(const char *name, bool default_value) const
void void
ConfigBlock::ThrowWithNested() const ConfigBlock::ThrowWithNested() const
{ {
std::throw_with_nested(FormatRuntimeError("Error in block on line %i", std::throw_with_nested(FmtRuntimeError("Error in block on line {}",
line)); line));
} }

View File

@ -20,7 +20,7 @@
#include "Data.hxx" #include "Data.hxx"
#include "Parser.hxx" #include "Parser.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include "util/StringAPI.hxx" #include "util/StringAPI.hxx"
#include <stdlib.h> #include <stdlib.h>
@ -157,7 +157,7 @@ ConfigData::FindBlock(ConfigBlockOption option,
for (const auto &block : GetBlockList(option)) { for (const auto &block : GetBlockList(option)) {
const char *value2 = block.GetBlockValue(key); const char *value2 = block.GetBlockValue(key);
if (value2 == nullptr) if (value2 == nullptr)
throw FormatRuntimeError("block without '%s' in line %d", throw FmtRuntimeError("block without '{}' in line {}",
key, block.line); key, block.line);
if (StringIsEqual(value2, value)) if (StringIsEqual(value2, value))

View File

@ -23,12 +23,12 @@
#include "Block.hxx" #include "Block.hxx"
#include "Templates.hxx" #include "Templates.hxx"
#include "lib/fmt/PathFormatter.hxx" #include "lib/fmt/PathFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "system/Error.hxx" #include "system/Error.hxx"
#include "util/Tokenizer.hxx" #include "util/Tokenizer.hxx"
#include "util/StringStrip.hxx" #include "util/StringStrip.hxx"
#include "util/StringAPI.hxx" #include "util/StringAPI.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/RuntimeError.hxx"
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "fs/List.hxx" #include "fs/List.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
@ -70,7 +70,7 @@ config_read_name_value(ConfigBlock &block, char *input, unsigned line)
const BlockParam *bp = block.GetBlockParam(name); const BlockParam *bp = block.GetBlockParam(name);
if (bp != nullptr) if (bp != nullptr)
throw FormatRuntimeError("\"%s\" is duplicate, first defined on line %i", throw FmtRuntimeError("\"{}\" is duplicate, first defined on line {}",
name, bp->line); name, bp->line);
block.AddBlockParam(name, value, line); block.AddBlockParam(name, value, line);
@ -123,8 +123,8 @@ ReadConfigBlock(ConfigData &config_data, BufferedReader &reader,
if (!option.repeatable) if (!option.repeatable)
if (const auto *block = config_data.GetBlock(o)) if (const auto *block = config_data.GetBlock(o))
throw FormatRuntimeError("config parameter \"%s\" is first defined " throw FmtRuntimeError("config parameter \"{}\" is first defined "
"on line %d and redefined on line %u\n", "on line {} and redefined on line {}",
name, block->line, name, block->line,
reader.GetLineNumber()); reader.GetLineNumber());
@ -227,7 +227,7 @@ ReadConfigFile(ConfigData &config_data, BufferedReader &reader, Path directory)
ReadConfigBlock(config_data, reader, name, bo, ReadConfigBlock(config_data, reader, name, bo,
tokenizer); tokenizer);
} else { } else {
throw FormatRuntimeError("unrecognized parameter: %s\n", throw FmtRuntimeError("unrecognized parameter: {}",
name); name);
} }
} }
@ -247,9 +247,8 @@ ReadConfigFile(ConfigData &config_data, Path path)
try { try {
ReadConfigFile(config_data, reader, path.GetDirectoryName()); ReadConfigFile(config_data, reader, path.GetDirectoryName());
} catch (...) { } catch (...) {
const std::string path_utf8 = path.ToUTF8(); std::throw_with_nested(FmtRuntimeError("Error in {} line {}",
std::throw_with_nested(FormatRuntimeError("Error in %s line %u", path,
path_utf8.c_str(),
reader.GetLineNumber())); reader.GetLineNumber()));
} }
} }

View File

@ -20,14 +20,14 @@
#include "Param.hxx" #include "Param.hxx"
#include "Path.hxx" #include "Path.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include <stdexcept> #include <stdexcept>
void void
ConfigParam::ThrowWithNested() const ConfigParam::ThrowWithNested() const
{ {
std::throw_with_nested(FormatRuntimeError("Error on line %i", line)); std::throw_with_nested(FmtRuntimeError("Error on line {}", line));
} }
AllocatedPath AllocatedPath

View File

@ -18,7 +18,7 @@
*/ */
#include "Parser.hxx" #include "Parser.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include "util/StringStrip.hxx" #include "util/StringStrip.hxx"
#include "util/StringUtil.hxx" #include "util/StringUtil.hxx"
@ -36,7 +36,7 @@ ParseBool(const char *value)
if (StringArrayContainsCase(f, value)) if (StringArrayContainsCase(f, value))
return false; return false;
throw FormatRuntimeError(R"(Not a valid boolean ("yes" or "no"): "%s")", value); throw FmtRuntimeError(R"(Not a valid boolean ("yes" or "no"): "{}")", value);
} }
long long

View File

@ -22,7 +22,7 @@
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "fs/Traits.hxx" #include "fs/Traits.hxx"
#include "fs/StandardDirectory.hxx" #include "fs/StandardDirectory.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include "util/StringSplit.hxx" #include "util/StringSplit.hxx"
#include <cassert> #include <cassert>
@ -40,7 +40,7 @@ GetHome(const char *user)
{ {
AllocatedPath result = GetHomeDir(user); AllocatedPath result = GetHomeDir(user);
if (result.IsNull()) if (result.IsNull())
throw FormatRuntimeError("no such user: %s", user); throw FmtRuntimeError("no such user: {}", user);
return result; return result;
} }
@ -107,7 +107,7 @@ ParsePath(const char *path)
/ AllocatedPath::FromUTF8Throw(rest); / AllocatedPath::FromUTF8Throw(rest);
} }
} else if (!PathTraitsUTF8::IsAbsolute(path)) { } else if (!PathTraitsUTF8::IsAbsolute(path)) {
throw FormatRuntimeError("not an absolute path: %s", path); throw FmtRuntimeError("not an absolute path: {}", path);
} else { } else {
#endif #endif
return AllocatedPath::FromUTF8Throw(path); return AllocatedPath::FromUTF8Throw(path);

View File

@ -22,7 +22,7 @@
#include "Domain.hxx" #include "Domain.hxx"
#include "Parser.hxx" #include "Parser.hxx"
#include "pcm/AudioParser.hxx" #include "pcm/AudioParser.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include "Log.hxx" #include "Log.hxx"
#include "MusicChunk.hxx" #include "MusicChunk.hxx"
@ -38,7 +38,7 @@ GetBufferChunks(const ConfigData &config)
buffer_size = param->With([](const char *s){ buffer_size = param->With([](const char *s){
size_t result = ParseSize(s, KILOBYTE); size_t result = ParseSize(s, KILOBYTE);
if (result <= 0) if (result <= 0)
throw FormatRuntimeError("buffer size \"%s\" is not a " throw FmtRuntimeError("buffer size \"{}\" is not a "
"positive integer", s); "positive integer", s);
if (result < MIN_BUFFER_SIZE) { if (result < MIN_BUFFER_SIZE) {
@ -53,8 +53,8 @@ GetBufferChunks(const ConfigData &config)
unsigned buffer_chunks = buffer_size / CHUNK_SIZE; unsigned buffer_chunks = buffer_size / CHUNK_SIZE;
if (buffer_chunks >= 1 << 15) if (buffer_chunks >= 1 << 15)
throw FormatRuntimeError("buffer size \"%lu\" is too big", throw FmtRuntimeError("buffer size \"{}\" is too big",
(unsigned long)buffer_size); buffer_size);
return buffer_chunks; return buffer_chunks;
} }

View File

@ -14,6 +14,7 @@ config = static_library(
include_directories: inc, include_directories: inc,
dependencies: [ dependencies: [
log_dep, log_dep,
fmt_dep,
], ],
) )

View File

@ -26,7 +26,7 @@
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "fs/StandardDirectory.hxx" #include "fs/StandardDirectory.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
DatabasePtr DatabasePtr
CreateConfiguredDatabase(const ConfigData &config, CreateConfiguredDatabase(const ConfigData &config,
@ -37,7 +37,7 @@ CreateConfiguredDatabase(const ConfigData &config,
const auto *path = config.GetParam(ConfigOption::DB_FILE); const auto *path = config.GetParam(ConfigOption::DB_FILE);
if (param != nullptr && path != nullptr) if (param != nullptr && path != nullptr)
throw FormatRuntimeError("Found both 'database' (line %d) and 'db_file' (line %d) setting", throw FmtRuntimeError("Found both 'database' (line {}) and 'db_file' (line }) setting",
param->line, path->line); param->line, path->line);
if (param != nullptr) { if (param != nullptr) {

View File

@ -18,11 +18,11 @@
*/ */
#include "DatabaseGlue.hxx" #include "DatabaseGlue.hxx"
#include "DatabasePlugin.hxx"
#include "Interface.hxx" #include "Interface.hxx"
#include "Registry.hxx" #include "Registry.hxx"
#include "util/RuntimeError.hxx"
#include "config/Block.hxx" #include "config/Block.hxx"
#include "DatabasePlugin.hxx" #include "lib/fmt/RuntimeError.hxx"
DatabasePtr DatabasePtr
DatabaseGlobalInit(EventLoop &main_event_loop, DatabaseGlobalInit(EventLoop &main_event_loop,
@ -35,14 +35,14 @@ DatabaseGlobalInit(EventLoop &main_event_loop,
const DatabasePlugin *plugin = GetDatabasePluginByName(plugin_name); const DatabasePlugin *plugin = GetDatabasePluginByName(plugin_name);
if (plugin == nullptr) if (plugin == nullptr)
throw FormatRuntimeError("No such database plugin: %s", throw FmtRuntimeError("No such database plugin: {}",
plugin_name); plugin_name);
try { try {
return plugin->create(main_event_loop, io_event_loop, return plugin->create(main_event_loop, io_event_loop,
listener, block); listener, block);
} catch (...) { } catch (...) {
std::throw_with_nested(FormatRuntimeError("Failed to initialize database plugin '%s'", std::throw_with_nested(FmtRuntimeError("Failed to initialize database plugin '{}'",
plugin_name)); plugin_name));
} }
} }

View File

@ -37,9 +37,9 @@
#include "tag/Builder.hxx" #include "tag/Builder.hxx"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "tag/ParseName.hxx" #include "tag/ParseName.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/RecursiveMap.hxx" #include "util/RecursiveMap.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
#include "util/RuntimeError.hxx"
#include "protocol/Ack.hxx" #include "protocol/Ack.hxx"
#include "event/SocketEvent.hxx" #include "event/SocketEvent.hxx"
#include "event/IdleEvent.hxx" #include "event/IdleEvent.hxx"
@ -507,7 +507,7 @@ ProxyDatabase::Connect()
if (mpd_connection_cmp_server_version(connection, 0, 20, 0) < 0) { if (mpd_connection_cmp_server_version(connection, 0, 20, 0) < 0) {
const unsigned *version = const unsigned *version =
mpd_connection_get_server_version(connection); mpd_connection_get_server_version(connection);
throw FormatRuntimeError("Connect to MPD %u.%u.%u, but this " throw FmtRuntimeError("Connect to MPD {}.{}.{}, but this "
"plugin requires at least version 0.20", "plugin requires at least version 0.20",
version[0], version[1], version[2]); version[0], version[1], version[2]);
} }
@ -521,8 +521,8 @@ ProxyDatabase::Connect()
std::throw_with_nested(host.empty() std::throw_with_nested(host.empty()
? std::runtime_error("Failed to connect to remote MPD") ? std::runtime_error("Failed to connect to remote MPD")
: FormatRuntimeError("Failed to connect to remote MPD '%s'", : FmtRuntimeError("Failed to connect to remote MPD '{}'",
host.c_str())); host));
} }
mpd_connection_set_keepalive(connection, keepalive); mpd_connection_set_keepalive(connection, keepalive);

View File

@ -20,13 +20,13 @@
#include "DatabaseSave.hxx" #include "DatabaseSave.hxx"
#include "db/DatabaseLock.hxx" #include "db/DatabaseLock.hxx"
#include "DirectorySave.hxx" #include "DirectorySave.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "io/BufferedOutputStream.hxx" #include "io/BufferedOutputStream.hxx"
#include "io/LineReader.hxx" #include "io/LineReader.hxx"
#include "tag/ParseName.hxx" #include "tag/ParseName.hxx"
#include "tag/Settings.hxx" #include "tag/Settings.hxx"
#include "fs/Charset.hxx" #include "fs/Charset.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
#include "util/RuntimeError.hxx"
#include "Version.h" #include "Version.h"
#include <fmt/format.h> #include <fmt/format.h>
@ -102,21 +102,21 @@ db_load_internal(LineReader &file, Directory &music_root)
const char *const old_charset = GetFSCharset(); const char *const old_charset = GetFSCharset();
if (*old_charset != 0 if (*old_charset != 0
&& strcmp(new_charset, old_charset) != 0) && strcmp(new_charset, old_charset) != 0)
throw FormatRuntimeError("Existing database has charset " throw FmtRuntimeError("Existing database has charset "
"\"%s\" instead of \"%s\"; " "\"{}\" instead of \"{}\"; "
"discarding database file", "discarding database file",
new_charset, old_charset); new_charset, old_charset);
} else if ((p = StringAfterPrefix(line, DB_TAG_PREFIX))) { } else if ((p = StringAfterPrefix(line, DB_TAG_PREFIX))) {
const char *name = p; const char *name = p;
TagType tag = tag_name_parse(name); TagType tag = tag_name_parse(name);
if (tag == TAG_NUM_OF_ITEM_TYPES) if (tag == TAG_NUM_OF_ITEM_TYPES)
throw FormatRuntimeError("Unrecognized tag '%s', " throw FmtRuntimeError("Unrecognized tag '{}', "
"discarding database file", "discarding database file",
name); name);
tags[tag] = true; tags[tag] = true;
} else { } else {
throw FormatRuntimeError("Malformed line: %s", line); throw FmtRuntimeError("Malformed line: {}", line);
} }
} }

View File

@ -26,10 +26,10 @@
#include "io/LineReader.hxx" #include "io/LineReader.hxx"
#include "io/BufferedOutputStream.hxx" #include "io/BufferedOutputStream.hxx"
#include "time/ChronoUtil.hxx" #include "time/ChronoUtil.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/StringAPI.hxx" #include "util/StringAPI.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
#include "util/NumberParser.hxx" #include "util/NumberParser.hxx"
#include "util/RuntimeError.hxx"
#include <fmt/format.h> #include <fmt/format.h>
@ -126,8 +126,7 @@ static Directory *
directory_load_subdir(LineReader &file, Directory &parent, std::string_view name) directory_load_subdir(LineReader &file, Directory &parent, std::string_view name)
{ {
if (parent.FindChild(name) != nullptr) if (parent.FindChild(name) != nullptr)
throw FormatRuntimeError("Duplicate subdirectory '%.*s'", throw FmtRuntimeError("Duplicate subdirectory '{}'", name);
int(name.size()), name.data());
Directory *directory = parent.CreateChild(name); Directory *directory = parent.CreateChild(name);
@ -141,7 +140,7 @@ directory_load_subdir(LineReader &file, Directory &parent, std::string_view name
break; break;
if (!ParseLine(*directory, line)) if (!ParseLine(*directory, line))
throw FormatRuntimeError("Malformed line: %s", line); throw FmtRuntimeError("Malformed line: {}", line);
} }
directory_load(file, *directory); directory_load(file, *directory);
@ -167,7 +166,8 @@ directory_load(LineReader &file, Directory &directory)
const char *name = p; const char *name = p;
if (directory.FindSong(name) != nullptr) if (directory.FindSong(name) != nullptr)
throw FormatRuntimeError("Duplicate song '%s'", name); throw FmtRuntimeError("Duplicate song '{}'",
name);
std::string target; std::string target;
auto detached_song = song_load(file, name, auto detached_song = song_load(file, name,
@ -182,7 +182,7 @@ directory_load(LineReader &file, Directory &directory)
const char *name = p; const char *name = p;
playlist_metadata_load(file, directory.playlists, name); playlist_metadata_load(file, directory.playlists, name);
} else { } else {
throw FormatRuntimeError("Malformed line: %s", line); throw FmtRuntimeError("Malformed line: {}", line);
} }
} }
} }

View File

@ -27,7 +27,6 @@
#include "lib/upnp/Error.hxx" #include "lib/upnp/Error.hxx"
#include "Directory.hxx" #include "Directory.hxx"
#include "util/NumberParser.hxx" #include "util/NumberParser.hxx"
#include "util/RuntimeError.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
#include "util/StringFormat.hxx" #include "util/StringFormat.hxx"

View File

@ -23,6 +23,7 @@
#include "Domain.hxx" #include "Domain.hxx"
#include "decoder/Features.h" #include "decoder/Features.h"
#include "lib/fmt/ExceptionFormatter.hxx" #include "lib/fmt/ExceptionFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "config/Data.hxx" #include "config/Data.hxx"
#include "config/Block.hxx" #include "config/Block.hxx"
#include "plugins/AudiofileDecoderPlugin.hxx" #include "plugins/AudiofileDecoderPlugin.hxx"
@ -47,7 +48,6 @@
#include "plugins/MpcdecDecoderPlugin.hxx" #include "plugins/MpcdecDecoderPlugin.hxx"
#include "plugins/FluidsynthDecoderPlugin.hxx" #include "plugins/FluidsynthDecoderPlugin.hxx"
#include "plugins/SidplayDecoderPlugin.hxx" #include "plugins/SidplayDecoderPlugin.hxx"
#include "util/RuntimeError.hxx"
#include "Log.hxx" #include "Log.hxx"
#include "PluginUnavailable.hxx" #include "PluginUnavailable.hxx"
@ -164,7 +164,7 @@ decoder_plugin_init_all(const ConfigData &config)
"Decoder plugin '{}' is unavailable: {}", "Decoder plugin '{}' is unavailable: {}",
plugin.name, std::current_exception()); plugin.name, std::current_exception());
} catch (...) { } catch (...) {
std::throw_with_nested(FormatRuntimeError("Failed to initialize decoder plugin '%s'", std::throw_with_nested(FmtRuntimeError("Failed to initialize decoder plugin '{}'",
plugin.name)); plugin.name));
} }
} }

View File

@ -29,11 +29,11 @@
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "input/Registry.hxx" #include "input/Registry.hxx"
#include "DecoderList.hxx" #include "DecoderList.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "system/Error.hxx" #include "system/Error.hxx"
#include "util/MimeType.hxx" #include "util/MimeType.hxx"
#include "util/UriExtract.hxx" #include "util/UriExtract.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include "util/RuntimeError.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
@ -455,7 +455,7 @@ try {
if (!allocated.empty()) if (!allocated.empty())
error_uri = allocated.c_str(); error_uri = allocated.c_str();
std::throw_with_nested(FormatRuntimeError("Failed to decode %s", std::throw_with_nested(FmtRuntimeError("Failed to decode {}",
error_uri)); error_uri));
} }
@ -521,7 +521,7 @@ decoder_run_song(DecoderControl &dc,
if (!allocated.empty()) if (!allocated.empty())
error_uri = allocated.c_str(); error_uri = allocated.c_str();
throw FormatRuntimeError("Failed to decode %s", error_uri); throw FmtRuntimeError("Failed to decode {}", error_uri);
} }
dc.client_cond.notify_one(); dc.client_cond.notify_one();

View File

@ -20,7 +20,7 @@
#include "FlacPcm.hxx" #include "FlacPcm.hxx"
#include "pcm/CheckAudioFormat.hxx" #include "pcm/CheckAudioFormat.hxx"
#include "lib/xiph/FlacAudioFormat.hxx" #include "lib/xiph/FlacAudioFormat.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include <cassert> #include <cassert>
@ -30,7 +30,7 @@ FlacPcmImport::Open(unsigned sample_rate, unsigned bits_per_sample,
{ {
auto sample_format = FlacSampleFormat(bits_per_sample); auto sample_format = FlacSampleFormat(bits_per_sample);
if (sample_format == SampleFormat::UNDEFINED) if (sample_format == SampleFormat::UNDEFINED)
throw FormatRuntimeError("Unsupported FLAC bit depth: %u", throw FmtRuntimeError("Unsupported FLAC bit depth: {}",
bits_per_sample); bits_per_sample);
audio_format = CheckAudioFormat(sample_rate, sample_format, channels); audio_format = CheckAudioFormat(sample_rate, sample_format, channels);

View File

@ -21,10 +21,10 @@
#include "MikmodDecoderPlugin.hxx" #include "MikmodDecoderPlugin.hxx"
#include "../DecoderAPI.hxx" #include "../DecoderAPI.hxx"
#include "lib/fmt/PathFormatter.hxx" #include "lib/fmt/PathFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "tag/Handler.hxx" #include "tag/Handler.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/RuntimeError.hxx"
#include "Log.hxx" #include "Log.hxx"
#include "Version.h" #include "Version.h"
@ -111,7 +111,7 @@ mikmod_decoder_init(const ConfigBlock &block)
mikmod_loop = block.GetBlockValue("loop", false); mikmod_loop = block.GetBlockValue("loop", false);
mikmod_sample_rate = block.GetPositiveValue("sample_rate", 44100U); mikmod_sample_rate = block.GetPositiveValue("sample_rate", 44100U);
if (!audio_valid_sample_rate(mikmod_sample_rate)) if (!audio_valid_sample_rate(mikmod_sample_rate))
throw FormatRuntimeError("Invalid sample rate in line %d: %u", throw FmtRuntimeError("Invalid sample rate in line {}: {}",
block.line, mikmod_sample_rate); block.line, mikmod_sample_rate);
md_device = 0; md_device = 0;

View File

@ -22,8 +22,8 @@
#include "../DecoderAPI.hxx" #include "../DecoderAPI.hxx"
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "tag/Handler.hxx" #include "tag/Handler.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/RuntimeError.hxx"
#include "Log.hxx" #include "Log.hxx"
#ifdef _WIN32 #ifdef _WIN32
@ -56,13 +56,13 @@ modplug_decoder_init(const ConfigBlock &block)
} else if (strcmp(modplug_resampling_mode_value, "fir") == 0) { } else if (strcmp(modplug_resampling_mode_value, "fir") == 0) {
modplug_resampling_mode = MODPLUG_RESAMPLE_FIR; modplug_resampling_mode = MODPLUG_RESAMPLE_FIR;
} else { } else {
throw FormatRuntimeError("Invalid resampling mode in line %d: %s", throw FmtRuntimeError("Invalid resampling mode in line {}: {}",
block.line, modplug_resampling_mode_value); block.line, modplug_resampling_mode_value);
} }
modplug_loop_count = block.GetBlockValue("loop_count", 0); modplug_loop_count = block.GetBlockValue("loop_count", 0);
if (modplug_loop_count < -1) if (modplug_loop_count < -1)
throw FormatRuntimeError("Invalid loop count in line %d: %i", throw FmtRuntimeError("Invalid loop count in line {}: {}",
block.line, modplug_loop_count); block.line, modplug_loop_count);
return true; return true;

View File

@ -25,7 +25,6 @@
#include "tag/Handler.hxx" #include "tag/Handler.hxx"
#include "tag/Type.h" #include "tag/Type.h"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/RuntimeError.hxx"
#include "Log.hxx" #include "Log.hxx"
#include <libopenmpt/libopenmpt.hpp> #include <libopenmpt/libopenmpt.hpp>

View File

@ -24,6 +24,7 @@
#include "OpusTags.hxx" #include "OpusTags.hxx"
#include "lib/xiph/OggPacket.hxx" #include "lib/xiph/OggPacket.hxx"
#include "lib/xiph/OggFind.hxx" #include "lib/xiph/OggFind.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "../DecoderAPI.hxx" #include "../DecoderAPI.hxx"
#include "decoder/Reader.hxx" #include "decoder/Reader.hxx"
#include "input/Reader.hxx" #include "input/Reader.hxx"
@ -31,7 +32,6 @@
#include "tag/Handler.hxx" #include "tag/Handler.hxx"
#include "tag/Builder.hxx" #include "tag/Builder.hxx"
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "util/RuntimeError.hxx"
#include "Log.hxx" #include "Log.hxx"
#include <opus.h> #include <opus.h>
@ -206,7 +206,7 @@ MPDOpusDecoder::OnOggBeginning(const ogg_packet &packet)
assert(IsInitialized() == (output_buffer != nullptr)); assert(IsInitialized() == (output_buffer != nullptr));
if (IsInitialized() && channels != previous_channels) if (IsInitialized() && channels != previous_channels)
throw FormatRuntimeError("Next stream has different channels (%u -> %u)", throw FmtRuntimeError("Next stream has different channels ({} -> {})",
previous_channels, channels); previous_channels, channels);
/* TODO: parse attributes from the OpusHead (sample rate, /* TODO: parse attributes from the OpusHead (sample rate,
@ -216,7 +216,7 @@ MPDOpusDecoder::OnOggBeginning(const ogg_packet &packet)
opus_decoder = opus_decoder_create(opus_sample_rate, channels, opus_decoder = opus_decoder_create(opus_sample_rate, channels,
&opus_error); &opus_error);
if (opus_decoder == nullptr) if (opus_decoder == nullptr)
throw FormatRuntimeError("libopus error: %s", throw FmtRuntimeError("libopus error: {}",
opus_strerror(opus_error)); opus_strerror(opus_error));
if (IsInitialized()) { if (IsInitialized()) {
@ -318,7 +318,7 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet)
0); 0);
if (gcc_unlikely(nframes <= 0)) { if (gcc_unlikely(nframes <= 0)) {
if (nframes < 0) if (nframes < 0)
throw FormatRuntimeError("libopus error: %s", throw FmtRuntimeError("libopus error: {}",
opus_strerror(nframes)); opus_strerror(nframes));
else else
return; return;

View File

@ -25,17 +25,17 @@
#include "song/DetachedSong.hxx" #include "song/DetachedSong.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "lib/fmt/PathFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "lib/icu/Converter.hxx" #include "lib/icu/Converter.hxx"
#ifdef HAVE_SIDPLAYFP #ifdef HAVE_SIDPLAYFP
#include "io/FileReader.hxx" #include "io/FileReader.hxx"
#include "util/RuntimeError.hxx"
#endif #endif
#include "util/StringFormat.hxx" #include "util/StringFormat.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/AllocatedString.hxx" #include "util/AllocatedString.hxx"
#include "util/CharUtil.hxx" #include "util/CharUtil.hxx"
#include "util/ByteOrder.hxx" #include "util/ByteOrder.hxx"
#include "util/RuntimeError.hxx"
#include "Log.hxx" #include "Log.hxx"
#ifdef HAVE_SIDPLAYFP #ifdef HAVE_SIDPLAYFP
@ -88,10 +88,7 @@ static void loadRom(const Path rom_path, uint8_t *dump)
{ {
FileReader romDump(rom_path); FileReader romDump(rom_path);
if (romDump.Read(dump, rom_size) != rom_size) if (romDump.Read(dump, rom_size) != rom_size)
{ throw FmtRuntimeError("Could not load rom dump '{}'", rom_path);
throw FormatRuntimeError
("Could not load rom dump '%s'", rom_path.c_str());
}
} }
#endif #endif
@ -108,8 +105,8 @@ sidplay_load_songlength_db(const Path path)
bool error = db->open(path.c_str()) < 0; bool error = db->open(path.c_str()) < 0;
#endif #endif
if (error) if (error)
throw FormatRuntimeError("unable to read songlengths file %s: %s", throw FmtRuntimeError("unable to read songlengths file {}: {}",
path.c_str(), db->error()); path, db->error());
return db; return db;
} }

View File

@ -24,10 +24,11 @@
#include "pcm/CheckAudioFormat.hxx" #include "pcm/CheckAudioFormat.hxx"
#include "tag/Handler.hxx" #include "tag/Handler.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "lib/fmt/PathFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/AllocatedString.hxx" #include "util/AllocatedString.hxx"
#include "util/Math.hxx" #include "util/Math.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
#include "util/RuntimeError.hxx"
#include <wavpack/wavpack.h> #include <wavpack/wavpack.h>
@ -54,8 +55,8 @@ WavpackOpenInput(Path path, int flags, int norm_offset)
auto *wpc = WavpackOpenFileInput(path.c_str(), error, auto *wpc = WavpackOpenFileInput(path.c_str(), error,
flags, norm_offset); flags, norm_offset);
if (wpc == nullptr) if (wpc == nullptr)
throw FormatRuntimeError("failed to open WavPack file \"%s\": %s", throw FmtRuntimeError("failed to open WavPack file \"{}\": {}",
path.c_str(), error); path, error);
return wpc; return wpc;
} }
@ -72,7 +73,7 @@ WavpackOpenInput(const WavpackStreamReader64 &reader, void *wv_id, void *wvc_id,
wv_id, wvc_id, error, wv_id, wvc_id, error,
flags, norm_offset); flags, norm_offset);
if (wpc == nullptr) if (wpc == nullptr)
throw FormatRuntimeError("failed to open WavPack stream: %s", throw FmtRuntimeError("failed to open WavPack stream: {}",
error); error);
return wpc; return wpc;

View File

@ -21,8 +21,8 @@
#include "EncoderList.hxx" #include "EncoderList.hxx"
#include "EncoderPlugin.hxx" #include "EncoderPlugin.hxx"
#include "config/Block.hxx" #include "config/Block.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/StringAPI.hxx" #include "util/StringAPI.hxx"
#include "util/RuntimeError.hxx"
static const EncoderPlugin & static const EncoderPlugin &
GetConfiguredEncoderPlugin(const ConfigBlock &block, bool shout_legacy) GetConfiguredEncoderPlugin(const ConfigBlock &block, bool shout_legacy)
@ -43,7 +43,7 @@ GetConfiguredEncoderPlugin(const ConfigBlock &block, bool shout_legacy)
const auto plugin = encoder_plugin_get(name); const auto plugin = encoder_plugin_get(name);
if (plugin == nullptr) if (plugin == nullptr)
throw FormatRuntimeError("No such encoder: %s", name); throw FmtRuntimeError("No such encoder: {}", name);
return *plugin; return *plugin;
} }

View File

@ -35,6 +35,9 @@ encoder_glue = static_library(
'ToOutputStream.cxx', 'ToOutputStream.cxx',
'EncoderList.cxx', 'EncoderList.cxx',
include_directories: inc, include_directories: inc,
dependencies: [
fmt_dep,
],
) )
encoder_glue_dep = declare_dependency( encoder_glue_dep = declare_dependency(

View File

@ -21,8 +21,8 @@
#include "../EncoderAPI.hxx" #include "../EncoderAPI.hxx"
#include "pcm/AudioFormat.hxx" #include "pcm/AudioFormat.hxx"
#include "pcm/Buffer.hxx" #include "pcm/Buffer.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/DynamicFifoBuffer.hxx" #include "util/DynamicFifoBuffer.hxx"
#include "util/RuntimeError.hxx"
#include "util/Serial.hxx" #include "util/Serial.hxx"
#include "util/SpanCast.hxx" #include "util/SpanCast.hxx"
#include "util/StringUtil.hxx" #include "util/StringUtil.hxx"
@ -147,25 +147,25 @@ flac_encoder_setup(FLAC__StreamEncoder *fse, unsigned compression, bool oggflac,
} }
if (!FLAC__stream_encoder_set_compression_level(fse, compression)) if (!FLAC__stream_encoder_set_compression_level(fse, compression))
throw FormatRuntimeError("error setting flac compression to %d", throw FmtRuntimeError("error setting flac compression to {}",
compression); compression);
if (!FLAC__stream_encoder_set_channels(fse, audio_format.channels)) if (!FLAC__stream_encoder_set_channels(fse, audio_format.channels))
throw FormatRuntimeError("error setting flac channels num to %d", throw FmtRuntimeError("error setting flac channels num to {}",
audio_format.channels); audio_format.channels);
if (!FLAC__stream_encoder_set_bits_per_sample(fse, bits_per_sample)) if (!FLAC__stream_encoder_set_bits_per_sample(fse, bits_per_sample))
throw FormatRuntimeError("error setting flac bit format to %d", throw FmtRuntimeError("error setting flac bit format to {}",
bits_per_sample); bits_per_sample);
if (!FLAC__stream_encoder_set_sample_rate(fse, if (!FLAC__stream_encoder_set_sample_rate(fse,
audio_format.sample_rate)) audio_format.sample_rate))
throw FormatRuntimeError("error setting flac sample rate to %d", throw FmtRuntimeError("error setting flac sample rate to {}",
audio_format.sample_rate); audio_format.sample_rate);
if (oggflac && !FLAC__stream_encoder_set_ogg_serial_number(fse, if (oggflac && !FLAC__stream_encoder_set_ogg_serial_number(fse,
GenerateSerial())) GenerateSerial()))
throw FormatRuntimeError("error setting ogg serial number"); throw std::runtime_error{"error setting ogg serial number"};
} }
FlacEncoder::FlacEncoder(AudioFormat _audio_format, FLAC__StreamEncoder *_fse, unsigned _compression, bool _oggflac, bool _oggchaining) FlacEncoder::FlacEncoder(AudioFormat _audio_format, FLAC__StreamEncoder *_fse, unsigned _compression, bool _oggflac, bool _oggchaining)
@ -188,7 +188,7 @@ FlacEncoder::FlacEncoder(AudioFormat _audio_format, FLAC__StreamEncoder *_fse, u
this); this);
if (init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) if (init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
throw FormatRuntimeError("failed to initialize encoder: %s\n", throw FmtRuntimeError("failed to initialize encoder: {}",
FLAC__StreamEncoderInitStatusString[init_status]); FLAC__StreamEncoderInitStatusString[init_status]);
} }
@ -250,7 +250,7 @@ FlacEncoder::SendTag(const Tag &tag)
FLAC__metadata_object_delete(metadata); FLAC__metadata_object_delete(metadata);
if (init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) if (init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
throw FormatRuntimeError("failed to initialize encoder: %s\n", throw FmtRuntimeError("failed to initialize encoder: {}",
FLAC__StreamEncoderInitStatusString[init_status]); FLAC__StreamEncoderInitStatusString[init_status]);
} }

View File

@ -20,9 +20,9 @@
#include "LameEncoderPlugin.hxx" #include "LameEncoderPlugin.hxx"
#include "../EncoderAPI.hxx" #include "../EncoderAPI.hxx"
#include "pcm/AudioFormat.hxx" #include "pcm/AudioFormat.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/NumberParser.hxx" #include "util/NumberParser.hxx"
#include "util/ReusableArray.hxx" #include "util/ReusableArray.hxx"
#include "util/RuntimeError.hxx"
#include "util/SpanCast.hxx" #include "util/SpanCast.hxx"
#include <lame/lame.h> #include <lame/lame.h>
@ -79,7 +79,7 @@ PreparedLameEncoder::PreparedLameEncoder(const ConfigBlock &block)
quality = float(ParseDouble(value, &endptr)); quality = float(ParseDouble(value, &endptr));
if (*endptr != '\0' || quality < -1.0f || quality > 10.0f) if (*endptr != '\0' || quality < -1.0f || quality > 10.0f)
throw FormatRuntimeError("quality \"%s\" is not a number in the " throw FmtRuntimeError("quality \"{}\" is not a number in the "
"range -1 to 10", "range -1 to 10",
value); value);

View File

@ -20,8 +20,8 @@
#include "ShineEncoderPlugin.hxx" #include "ShineEncoderPlugin.hxx"
#include "../EncoderAPI.hxx" #include "../EncoderAPI.hxx"
#include "pcm/AudioFormat.hxx" #include "pcm/AudioFormat.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/DynamicFifoBuffer.hxx" #include "util/DynamicFifoBuffer.hxx"
#include "util/RuntimeError.hxx"
#include "util/SpanCast.hxx" #include "util/SpanCast.hxx"
extern "C" extern "C"
@ -121,8 +121,8 @@ SetupShine(shine_config_t config, AudioFormat &audio_format)
audio_format.channels == 2 ? PCM_STEREO : PCM_MONO; audio_format.channels == 2 ? PCM_STEREO : PCM_MONO;
if (shine_check_config(config.wave.samplerate, config.mpeg.bitr) < 0) if (shine_check_config(config.wave.samplerate, config.mpeg.bitr) < 0)
throw FormatRuntimeError("error configuring shine. " throw FmtRuntimeError("error configuring shine. "
"samplerate %d and bitrate %d configuration" "samplerate {} and bitrate {} configuration"
" not supported.", " not supported.",
config.wave.samplerate, config.wave.samplerate,
config.mpeg.bitr); config.mpeg.bitr);

View File

@ -20,8 +20,8 @@
#include "TwolameEncoderPlugin.hxx" #include "TwolameEncoderPlugin.hxx"
#include "../EncoderAPI.hxx" #include "../EncoderAPI.hxx"
#include "pcm/AudioFormat.hxx" #include "pcm/AudioFormat.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/NumberParser.hxx" #include "util/NumberParser.hxx"
#include "util/RuntimeError.hxx"
#include "util/SpanCast.hxx" #include "util/SpanCast.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx" #include "Log.hxx"
@ -96,7 +96,7 @@ PreparedTwolameEncoder::PreparedTwolameEncoder(const ConfigBlock &block)
quality = float(ParseDouble(value, &endptr)); quality = float(ParseDouble(value, &endptr));
if (*endptr != '\0' || quality < -1.0f || quality > 10.0f) if (*endptr != '\0' || quality < -1.0f || quality > 10.0f)
throw FormatRuntimeError("quality \"%s\" is not a number in the " throw FmtRuntimeError("quality \"{}\" is not a number in the "
"range -1 to 10", "range -1 to 10",
value); value);

View File

@ -19,12 +19,12 @@
#include "VorbisEncoderPlugin.hxx" #include "VorbisEncoderPlugin.hxx"
#include "OggEncoder.hxx" #include "OggEncoder.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "lib/xiph/VorbisComment.hxx" #include "lib/xiph/VorbisComment.hxx"
#include "pcm/AudioFormat.hxx" #include "pcm/AudioFormat.hxx"
#include "config/Domain.hxx" #include "config/Domain.hxx"
#include "util/StringUtil.hxx" #include "util/StringUtil.hxx"
#include "util/NumberParser.hxx" #include "util/NumberParser.hxx"
#include "util/RuntimeError.hxx"
#include <vorbis/vorbisenc.h> #include <vorbis/vorbisenc.h>
@ -88,7 +88,7 @@ PreparedVorbisEncoder::PreparedVorbisEncoder(const ConfigBlock &block)
quality = ParseDouble(value, &endptr); quality = ParseDouble(value, &endptr);
if (*endptr != '\0' || quality < -1.0f || quality > 10.0f) if (*endptr != '\0' || quality < -1.0f || quality > 10.0f)
throw FormatRuntimeError("quality \"%s\" is not a number in the " throw FmtRuntimeError("quality \"{}\" is not a number in the "
"range -1 to 10", "range -1 to 10",
value); value);

View File

@ -19,6 +19,7 @@
#include "ServerSocket.hxx" #include "ServerSocket.hxx"
#include "lib/fmt/ExceptionFormatter.hxx" #include "lib/fmt/ExceptionFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "net/IPv4Address.hxx" #include "net/IPv4Address.hxx"
#include "net/IPv6Address.hxx" #include "net/IPv6Address.hxx"
#include "net/StaticSocketAddress.hxx" #include "net/StaticSocketAddress.hxx"
@ -31,7 +32,6 @@
#include "net/ToString.hxx" #include "net/ToString.hxx"
#include "event/SocketEvent.hxx" #include "event/SocketEvent.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "util/RuntimeError.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx" #include "Log.hxx"
@ -255,8 +255,8 @@ ServerSocket::Open()
const auto address_string = i.ToString(); const auto address_string = i.ToString();
try { try {
std::throw_with_nested(FormatRuntimeError("Failed to bind to '%s'", std::throw_with_nested(FmtRuntimeError("Failed to bind to '{}'",
address_string.c_str())); address_string));
} catch (...) { } catch (...) {
last_error = std::current_exception(); last_error = std::current_exception();
} }

View File

@ -22,7 +22,7 @@
#include "Prepared.hxx" #include "Prepared.hxx"
#include "config/Data.hxx" #include "config/Data.hxx"
#include "config/Block.hxx" #include "config/Block.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
std::unique_ptr<PreparedFilter> std::unique_ptr<PreparedFilter>
FilterFactory::MakeFilter(const char *name) FilterFactory::MakeFilter(const char *name)
@ -30,7 +30,7 @@ FilterFactory::MakeFilter(const char *name)
const auto *cfg = config.FindBlock(ConfigBlockOption::AUDIO_FILTER, const auto *cfg = config.FindBlock(ConfigBlockOption::AUDIO_FILTER,
"name", name); "name", name);
if (cfg == nullptr) if (cfg == nullptr)
throw FormatRuntimeError("Filter template not found: %s", throw FmtRuntimeError("Filter template not found: {}",
name); name);
cfg->SetUsed(); cfg->SetUsed();

View File

@ -22,7 +22,7 @@
#include "Registry.hxx" #include "Registry.hxx"
#include "Prepared.hxx" #include "Prepared.hxx"
#include "config/Block.hxx" #include "config/Block.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
std::unique_ptr<PreparedFilter> std::unique_ptr<PreparedFilter>
filter_configured_new(const ConfigBlock &block) filter_configured_new(const ConfigBlock &block)
@ -33,7 +33,7 @@ filter_configured_new(const ConfigBlock &block)
const auto *plugin = filter_plugin_by_name(plugin_name); const auto *plugin = filter_plugin_by_name(plugin_name);
if (plugin == nullptr) if (plugin == nullptr)
throw FormatRuntimeError("No such filter plugin: %s", throw FmtRuntimeError("No such filter plugin: {}",
plugin_name); plugin_name);
return plugin->init(block); return plugin->init(block);

View File

@ -17,6 +17,9 @@ filter_glue = static_library(
'LoadOne.cxx', 'LoadOne.cxx',
'LoadChain.cxx', 'LoadChain.cxx',
include_directories: inc, include_directories: inc,
dependencies: [
fmt_dep,
],
) )
filter_glue_dep = declare_dependency( filter_glue_dep = declare_dependency(

View File

@ -47,8 +47,8 @@
#include "pcm/AudioFormat.hxx" #include "pcm/AudioFormat.hxx"
#include "pcm/Buffer.hxx" #include "pcm/Buffer.hxx"
#include "pcm/Silence.hxx" #include "pcm/Silence.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/StringStrip.hxx" #include "util/StringStrip.hxx"
#include "util/RuntimeError.hxx"
#include <array> #include <array>
#include <cstdint> #include <cstdint>
@ -159,7 +159,7 @@ PreparedRouteFilter::PreparedRouteFilter(const ConfigBlock &block)
throw std::runtime_error("Malformed 'routes' specification"); throw std::runtime_error("Malformed 'routes' specification");
if (source >= MAX_CHANNELS) if (source >= MAX_CHANNELS)
throw FormatRuntimeError("Invalid source channel number: %u", throw FmtRuntimeError("Invalid source channel number: {}",
source); source);
if (source >= min_input_channels) if (source >= min_input_channels)
@ -173,7 +173,7 @@ PreparedRouteFilter::PreparedRouteFilter(const ConfigBlock &block)
throw std::runtime_error("Malformed 'routes' specification"); throw std::runtime_error("Malformed 'routes' specification");
if (dest >= MAX_CHANNELS) if (dest >= MAX_CHANNELS)
throw FormatRuntimeError("Invalid destination channel number: %u", throw FmtRuntimeError("Invalid destination channel number: {}",
dest); dest);
if (dest >= min_output_channels) if (dest >= min_output_channels)

View File

@ -19,7 +19,8 @@
#include "TwoFilters.hxx" #include "TwoFilters.hxx"
#include "pcm/AudioFormat.hxx" #include "pcm/AudioFormat.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/AudioFormatFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/StringBuffer.hxx" #include "util/StringBuffer.hxx"
std::span<const std::byte> std::span<const std::byte>
@ -50,9 +51,8 @@ PreparedTwoFilters::Open(AudioFormat &audio_format)
auto b = second->Open(b_in_format); auto b = second->Open(b_in_format);
if (b_in_format != a_out_format) if (b_in_format != a_out_format)
throw FormatRuntimeError("Audio format not supported by filter '%s': %s", throw FmtRuntimeError("Audio format not supported by filter '{}': {}",
second_name.c_str(), second_name, a_out_format);
ToString(a_out_format).c_str());
return std::make_unique<TwoFilters>(std::move(a), return std::make_unique<TwoFilters>(std::move(a),
std::move(b)); std::move(b));

View File

@ -25,8 +25,8 @@
#include "config/Block.hxx" #include "config/Block.hxx"
#include "Log.hxx" #include "Log.hxx"
#include "PluginUnavailable.hxx" #include "PluginUnavailable.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/RuntimeError.hxx"
#include <cassert> #include <cassert>
#include <stdexcept> #include <stdexcept>
@ -80,7 +80,7 @@ input_stream_global_init(const ConfigData &config, EventLoop &event_loop)
plugin->name, e.what()); plugin->name, e.what());
continue; continue;
} catch (...) { } catch (...) {
std::throw_with_nested(FormatRuntimeError("Failed to initialize input plugin '%s'", std::throw_with_nested(FmtRuntimeError("Failed to initialize input plugin '{}'",
plugin->name)); plugin->name));
} }
} }

View File

@ -23,11 +23,11 @@
#include "CdioParanoiaInputPlugin.hxx" #include "CdioParanoiaInputPlugin.hxx"
#include "lib/cdio/Paranoia.hxx" #include "lib/cdio/Paranoia.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "../InputStream.hxx" #include "../InputStream.hxx"
#include "../InputPlugin.hxx" #include "../InputPlugin.hxx"
#include "util/TruncateString.hxx" #include "util/TruncateString.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
#include "util/RuntimeError.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/ByteOrder.hxx" #include "util/ByteOrder.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
@ -114,7 +114,7 @@ input_cdio_init(EventLoop &, const ConfigBlock &block)
else if (strcmp(value, "big_endian") == 0) else if (strcmp(value, "big_endian") == 0)
default_reverse_endian = IsLittleEndian(); default_reverse_endian = IsLittleEndian();
else else
throw FormatRuntimeError("Unrecognized 'default_byte_order' setting: %s", throw FmtRuntimeError("Unrecognized 'default_byte_order' setting: {}",
value); value);
} }
speed = block.GetBlockValue("speed",0U); speed = block.GetBlockValue("speed",0U);
@ -263,7 +263,7 @@ input_cdio_open(const char *uri,
default: default:
cdio_cddap_close_no_free_cdio(drv); cdio_cddap_close_no_free_cdio(drv);
cdio_destroy(cdio); cdio_destroy(cdio);
throw FormatRuntimeError("Drive returns unknown data type %d", throw FmtRuntimeError("Drive returns unknown data type {}",
be); be);
} }
@ -287,8 +287,8 @@ CdioParanoiaInputStream::Seek(std::unique_lock<Mutex> &,
offset_type new_offset) offset_type new_offset)
{ {
if (new_offset > size) if (new_offset > size)
throw FormatRuntimeError("Invalid offset to seek %ld (%ld)", throw FmtRuntimeError("Invalid offset to seek {} ({})",
(long int)new_offset, (long int)size); new_offset, size);
/* simple case */ /* simple case */
if (new_offset == offset) if (new_offset == offset)

View File

@ -21,11 +21,10 @@
#include "../InputStream.hxx" #include "../InputStream.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "fs/FileInfo.hxx" #include "fs/FileInfo.hxx"
#include "lib/fmt/PathFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "io/FileReader.hxx" #include "io/FileReader.hxx"
#include "io/FileDescriptor.hxx" #include "io/FileDescriptor.hxx"
#include "util/RuntimeError.hxx"
#include <cinttypes> // for PRIu64 (PRIoffset)
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
@ -63,8 +62,7 @@ OpenFileInputStream(Path path, Mutex &mutex)
const FileInfo info = reader.GetFileInfo(); const FileInfo info = reader.GetFileInfo();
if (!info.IsRegular()) if (!info.IsRegular())
throw FormatRuntimeError("Not a regular file: %s", throw FmtRuntimeError("Not a regular file: {}", path);
path.c_str());
#ifdef POSIX_FADV_SEQUENTIAL #ifdef POSIX_FADV_SEQUENTIAL
posix_fadvise(reader.GetFD().Get(), (off_t)0, info.GetSize(), posix_fadvise(reader.GetFD().Get(), (off_t)0, info.GetSize(),
@ -100,8 +98,8 @@ FileInputStream::Read(std::unique_lock<Mutex> &,
} }
if (nbytes == 0 && !IsEOF()) if (nbytes == 0 && !IsEOF())
throw FormatRuntimeError("Unexpected end of file %s" throw FmtRuntimeError("Unexpected end of file {}"
" at %" PRIoffset " of %" PRIoffset, " at {} of {}",
GetURI(), GetOffset(), GetSize()); GetURI(), GetOffset(), GetSize());
offset += nbytes; offset += nbytes;

View File

@ -19,8 +19,7 @@
#include "QobuzErrorParser.hxx" #include "QobuzErrorParser.hxx"
#include "lib/yajl/Callbacks.hxx" #include "lib/yajl/Callbacks.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
using std::string_view_literals::operator""sv; using std::string_view_literals::operator""sv;
@ -46,7 +45,7 @@ QobuzErrorParser::QobuzErrorParser(unsigned _status,
{ {
auto i = headers.find("content-type"); auto i = headers.find("content-type");
if (i == headers.end() || i->second.find("/json") == i->second.npos) if (i == headers.end() || i->second.find("/json") == i->second.npos)
throw FormatRuntimeError("Status %u from Qobuz", status); throw FmtRuntimeError("Status {} from Qobuz", status);
} }
void void
@ -55,10 +54,9 @@ QobuzErrorParser::OnEnd()
YajlResponseParser::OnEnd(); YajlResponseParser::OnEnd();
if (!message.empty()) if (!message.empty())
throw FormatRuntimeError("Error from Qobuz: %s", throw FmtRuntimeError("Error from Qobuz: {}", message);
message.c_str());
else else
throw FormatRuntimeError("Status %u from Qobuz", status); throw FmtRuntimeError("Status {} from Qobuz", status);
} }
inline bool inline bool

View File

@ -21,12 +21,12 @@
#include "../AsyncInputStream.hxx" #include "../AsyncInputStream.hxx"
#include "event/Call.hxx" #include "event/Call.hxx"
#include "event/Loop.hxx" #include "event/Loop.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "lib/fmt/SystemError.hxx" #include "lib/fmt/SystemError.hxx"
#include "io/Open.hxx" #include "io/Open.hxx"
#include "io/UniqueFileDescriptor.hxx" #include "io/UniqueFileDescriptor.hxx"
#include "io/uring/ReadOperation.hxx" #include "io/uring/ReadOperation.hxx"
#include "io/uring/Queue.hxx" #include "io/uring/Queue.hxx"
#include "util/RuntimeError.hxx"
#include <sys/stat.h> #include <sys/stat.h>
@ -191,7 +191,7 @@ OpenUringInputStream(const char *path, Mutex &mutex)
throw FmtErrno("Failed to access {}", path); throw FmtErrno("Failed to access {}", path);
if (!S_ISREG(st.st_mode)) if (!S_ISREG(st.st_mode))
throw FormatRuntimeError("Not a regular file: %s", path); throw FmtRuntimeError("Not a regular file: {}", path);
return std::make_unique<UringInputStream>(*uring_input_event_loop, return std::make_unique<UringInputStream>(*uring_input_event_loop,
*uring_input_queue, *uring_input_queue,

View File

@ -62,7 +62,7 @@ FileReader::Read(void *data, std::size_t size)
DWORD nbytes; DWORD nbytes;
if (!ReadFile(handle, data, size, &nbytes, nullptr)) if (!ReadFile(handle, data, size, &nbytes, nullptr))
throw FmtLastError("Failed to read from %s", path); throw FmtLastError("Failed to read from {}", path);
return nbytes; return nbytes;
} }

View File

@ -22,9 +22,9 @@
#include "Format.hxx" #include "Format.hxx"
#include "lib/fmt/AudioFormatFormatter.hxx" #include "lib/fmt/AudioFormatFormatter.hxx"
#include "lib/fmt/ToBuffer.hxx" #include "lib/fmt/ToBuffer.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/ByteOrder.hxx" #include "util/ByteOrder.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/RuntimeError.hxx"
#include "pcm/AudioFormat.hxx" #include "pcm/AudioFormat.hxx"
#include "Log.hxx" #include "Log.hxx"
#include "config.h" #include "config.h"
@ -224,7 +224,7 @@ SetupHw(snd_pcm_t *pcm,
requested_sample_rate)); requested_sample_rate));
if (output_sample_rate == 0) if (output_sample_rate == 0)
throw FormatRuntimeError("Failed to configure sample rate %u Hz", throw FmtRuntimeError("Failed to configure sample rate {} Hz",
audio_format.sample_rate); audio_format.sample_rate);
if (output_sample_rate != requested_sample_rate) if (output_sample_rate != requested_sample_rate)

View File

@ -20,7 +20,6 @@
#include "NonBlock.hxx" #include "NonBlock.hxx"
#include "Error.hxx" #include "Error.hxx"
#include "event/MultiSocketMonitor.hxx" #include "event/MultiSocketMonitor.hxx"
#include "util/RuntimeError.hxx"
Event::Duration Event::Duration
AlsaNonBlockPcm::PrepareSockets(MultiSocketMonitor &m, snd_pcm_t *pcm) AlsaNonBlockPcm::PrepareSockets(MultiSocketMonitor &m, snd_pcm_t *pcm)

View File

@ -31,12 +31,12 @@
*/ */
#include "Error.hxx" #include "Error.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
void void
ODBus::Error::Throw(const char *prefix) const ODBus::Error::Throw(const char *prefix) const
{ {
throw FormatRuntimeError("%s: %s", prefix, GetMessage()); throw FmtRuntimeError("{}: {}", prefix, GetMessage());
} }
void void

View File

@ -18,7 +18,7 @@
*/ */
#include "Error.hxx" #include "Error.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
extern "C" { extern "C" {
#include <libavutil/error.h> #include <libavutil/error.h>
@ -37,5 +37,5 @@ MakeFfmpegError(int errnum, const char *prefix)
{ {
char msg[256]; char msg[256];
av_strerror(errnum, msg, sizeof(msg)); av_strerror(errnum, msg, sizeof(msg));
return FormatRuntimeError("%s: %s", prefix, msg); return FmtRuntimeError("{}: {}", prefix, msg);
} }

View File

@ -21,7 +21,7 @@
#include "ChannelLayout.hxx" #include "ChannelLayout.hxx"
#include "SampleFormat.hxx" #include "SampleFormat.hxx"
#include "pcm/AudioFormat.hxx" #include "pcm/AudioFormat.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include <cinttypes> #include <cinttypes>
@ -34,7 +34,7 @@ RequireFilterByName(const char *name)
{ {
const auto *filter = avfilter_get_by_name(name); const auto *filter = avfilter_get_by_name(name);
if (filter == nullptr) if (filter == nullptr)
throw FormatRuntimeError("No such FFmpeg filter: '%s'", name); throw FmtRuntimeError("No such FFmpeg filter: '{}'", name);
return *filter; return *filter;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2013-2020 Max Kellermann <max.kellermann@gmail.com> * Copyright 2022 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -27,40 +27,19 @@
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef RUNTIME_ERROR_HXX #include "RuntimeError.hxx"
#define RUNTIME_ERROR_HXX #include "ToBuffer.hxx"
#include <stdexcept> // IWYU pragma: export std::runtime_error
#include <utility> VFmtRuntimeError(fmt::string_view format_str, fmt::format_args args) noexcept
#include <stdio.h>
#if defined(__clang__) || defined(__GNUC__)
#pragma GCC diagnostic push
// TODO: fix this warning properly
#pragma GCC diagnostic ignored "-Wformat-security"
#endif
template<typename... Args>
static inline std::runtime_error
FormatRuntimeError(const char *fmt, Args&&... args) noexcept
{ {
char buffer[1024]; const auto msg = VFmtBuffer<512>(format_str, args);
snprintf(buffer, sizeof(buffer), fmt, std::forward<Args>(args)...); return std::runtime_error{msg};
return std::runtime_error(buffer);
} }
template<typename... Args> std::invalid_argument
inline std::invalid_argument VFmtInvalidArgument(fmt::string_view format_str, fmt::format_args args) noexcept
FormatInvalidArgument(const char *fmt, Args&&... args) noexcept
{ {
char buffer[1024]; const auto msg = VFmtBuffer<512>(format_str, args);
snprintf(buffer, sizeof(buffer), fmt, std::forward<Args>(args)...); return std::invalid_argument{msg};
return std::invalid_argument(buffer);
} }
#if defined(__clang__) || defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
#endif

View File

@ -0,0 +1,75 @@
/*
* Copyright 2022 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <fmt/core.h>
#if FMT_VERSION >= 80000 && FMT_VERSION < 90000
#include <fmt/format.h>
#endif
#include <stdexcept> // IWYU pragma: export
[[nodiscard]] [[gnu::pure]]
std::runtime_error
VFmtRuntimeError(fmt::string_view format_str, fmt::format_args args) noexcept;
template<typename S, typename... Args>
[[nodiscard]] [[gnu::pure]]
auto
FmtRuntimeError(const S &format_str, Args&&... args) noexcept
{
#if FMT_VERSION >= 90000
return VFmtRuntimeError(format_str,
fmt::make_format_args(args...));
#else
return VFmtRuntimeError(fmt::to_string_view(format_str),
fmt::make_args_checked<Args...>(format_str,
args...));
#endif
}
[[nodiscard]] [[gnu::pure]]
std::invalid_argument
VFmtInvalidArgument(fmt::string_view format_str, fmt::format_args args) noexcept;
template<typename S, typename... Args>
[[nodiscard]] [[gnu::pure]]
auto
FmtInvalidArgument(const S &format_str, Args&&... args) noexcept
{
#if FMT_VERSION >= 90000
return VFmtInvalidArgument(format_str,
fmt::make_format_args(args...));
#else
return VFmtInvalidArgument(fmt::to_string_view(format_str),
fmt::make_args_checked<Args...>(format_str,
args...));
#endif
}

View File

@ -10,6 +10,7 @@ endif
fmt = static_library( fmt = static_library(
'fmt', 'fmt',
'RuntimeError.cxx',
'SystemError.cxx', 'SystemError.cxx',
include_directories: inc, include_directories: inc,
dependencies: libfmt, dependencies: libfmt,

View File

@ -21,7 +21,6 @@
#include "Collate.hxx" #include "Collate.hxx"
#include "Canonicalize.hxx" #include "Canonicalize.hxx"
#include "Error.hxx" #include "Error.hxx"
#include "util/RuntimeError.hxx"
#include <unicode/uclean.h> #include <unicode/uclean.h>

View File

@ -18,6 +18,7 @@
*/ */
#include "system/Error.hxx" #include "system/Error.hxx"
#include "lib/fmt/RuntimeError.hxx"
/* sorry for this horrible piece of code - there's no elegant way to /* sorry for this horrible piece of code - there's no elegant way to
load DLLs at runtime */ load DLLs at runtime */
@ -102,7 +103,7 @@ GetFunction(HMODULE h, const char *name, T &result)
{ {
auto f = GetProcAddress(h, name); auto f = GetProcAddress(h, name);
if (f == nullptr) if (f == nullptr)
throw FormatRuntimeError("No such libjack function: %s", name); throw FmtRuntimeError("No such libjack function: {}", name);
result = reinterpret_cast<T>(f); result = reinterpret_cast<T>(f);
} }

View File

@ -18,7 +18,6 @@
*/ */
#include "Error.hxx" #include "Error.hxx"
#include "util/RuntimeError.hxx"
#include <pulse/context.h> #include <pulse/context.h>
#include <pulse/error.h> #include <pulse/error.h>

View File

@ -28,7 +28,7 @@
*/ */
#include "Handle.hxx" #include "Handle.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
#include "util/StringStrip.hxx" #include "util/StringStrip.hxx"
@ -60,7 +60,7 @@ Handle::ThrowError()
yajl_free_error(handle, str); yajl_free_error(handle, str);
}; };
throw FormatRuntimeError("Failed to parse JSON: %s", throw FmtRuntimeError("Failed to parse JSON: {}",
StripErrorMessage((char *)str)); StripErrorMessage((char *)str));
} }

View File

@ -20,6 +20,7 @@
#include "AlsaMixerPlugin.hxx" #include "AlsaMixerPlugin.hxx"
#include "lib/alsa/NonBlock.hxx" #include "lib/alsa/NonBlock.hxx"
#include "lib/alsa/Error.hxx" #include "lib/alsa/Error.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "lib/fmt/ToBuffer.hxx" #include "lib/fmt/ToBuffer.hxx"
#include "mixer/Mixer.hxx" #include "mixer/Mixer.hxx"
#include "mixer/Listener.hxx" #include "mixer/Listener.hxx"
@ -30,7 +31,6 @@
#include "util/ASCII.hxx" #include "util/ASCII.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/Math.hxx" #include "util/Math.hxx"
#include "util/RuntimeError.hxx"
#include "Log.hxx" #include "Log.hxx"
extern "C" { extern "C" {
@ -279,7 +279,7 @@ AlsaMixer::Setup()
elem = alsa_mixer_lookup_elem(handle, control, index); elem = alsa_mixer_lookup_elem(handle, control, index);
if (elem == nullptr) if (elem == nullptr)
throw FormatRuntimeError("no such mixer control: %s", control); throw FmtRuntimeError("no such mixer control: {}", control);
snd_mixer_elem_set_callback_private(elem, this); snd_mixer_elem_set_callback_private(elem, this);
snd_mixer_elem_set_callback(elem, ElemCallback); snd_mixer_elem_set_callback(elem, ElemCallback);

View File

@ -20,11 +20,11 @@
#include "OssMixerPlugin.hxx" #include "OssMixerPlugin.hxx"
#include "mixer/Mixer.hxx" #include "mixer/Mixer.hxx"
#include "config/Block.hxx" #include "config/Block.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "io/FileDescriptor.hxx" #include "io/FileDescriptor.hxx"
#include "lib/fmt/SystemError.hxx" #include "lib/fmt/SystemError.hxx"
#include "util/ASCII.hxx" #include "util/ASCII.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/RuntimeError.hxx"
#include "Log.hxx" #include "Log.hxx"
#include <cassert> #include <cassert>
@ -91,7 +91,7 @@ OssMixer::Configure(const ConfigBlock &block)
if (control != NULL) { if (control != NULL) {
volume_control = oss_find_mixer(control); volume_control = oss_find_mixer(control);
if (volume_control < 0) if (volume_control < 0)
throw FormatRuntimeError("no such mixer control: %s", throw FmtRuntimeError("no such mixer control: {}",
control); control);
} else } else
volume_control = SOUND_MIXER_PCM; volume_control = SOUND_MIXER_PCM;

View File

@ -18,13 +18,13 @@
*/ */
#include "PulseMixerPlugin.hxx" #include "PulseMixerPlugin.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "lib/pulse/LogError.hxx" #include "lib/pulse/LogError.hxx"
#include "lib/pulse/LockGuard.hxx" #include "lib/pulse/LockGuard.hxx"
#include "mixer/Mixer.hxx" #include "mixer/Mixer.hxx"
#include "mixer/Listener.hxx" #include "mixer/Listener.hxx"
#include "output/plugins/PulseOutputPlugin.hxx" #include "output/plugins/PulseOutputPlugin.hxx"
#include "util/NumberParser.hxx" #include "util/NumberParser.hxx"
#include "util/RuntimeError.hxx"
#include "config/Block.hxx" #include "config/Block.hxx"
#include <pulse/context.h> #include <pulse/context.h>
@ -177,7 +177,7 @@ parse_volume_scale_factor(const char *value) {
float factor = ParseFloat(value, &endptr); float factor = ParseFloat(value, &endptr);
if (endptr == value || *endptr != '\0' || factor < 0.5f || factor > 5.0f) if (endptr == value || *endptr != '\0' || factor < 0.5f || factor > 5.0f)
throw FormatRuntimeError("\"%s\" is not a number in the " throw FmtRuntimeError("\"{}\" is not a number in the "
"range 0.5 to 5.0", "range 0.5 to 5.0",
value); value);

View File

@ -24,7 +24,7 @@
#include "Info.hxx" #include "Info.hxx"
#include "config/Data.hxx" #include "config/Data.hxx"
#include "config/Block.hxx" #include "config/Block.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include <stdexcept> #include <stdexcept>
@ -38,7 +38,7 @@ CreateNeighborExplorer(EventLoop &loop, NeighborListener &listener,
{ {
const NeighborPlugin *plugin = GetNeighborPluginByName(plugin_name); const NeighborPlugin *plugin = GetNeighborPluginByName(plugin_name);
if (plugin == nullptr) if (plugin == nullptr)
throw FormatRuntimeError("No such neighbor plugin: %s", throw FmtRuntimeError("No such neighbor plugin: {}",
plugin_name); plugin_name);
return plugin->create(loop, listener, block); return plugin->create(loop, listener, block);
@ -72,8 +72,8 @@ NeighborGlue::Open()
for (auto k = explorers.begin(); k != i; ++k) for (auto k = explorers.begin(); k != i; ++k)
k->explorer->Close(); k->explorer->Close();
std::throw_with_nested(FormatRuntimeError("Failed to open neighblor plugin '%s'", std::throw_with_nested(FmtRuntimeError("Failed to open neighblor plugin '{}'",
i->name.c_str())); i->name));
} }
} }
} }

View File

@ -33,7 +33,7 @@
#include "Resolver.hxx" #include "Resolver.hxx"
#include "AddressInfo.hxx" #include "AddressInfo.hxx"
#include "HostParser.hxx" #include "HostParser.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include "util/CharUtil.hxx" #include "util/CharUtil.hxx"
#ifdef _WIN32 #ifdef _WIN32
@ -54,11 +54,17 @@ Resolve(const char *node, const char *service,
{ {
struct addrinfo *ai; struct addrinfo *ai;
int error = getaddrinfo(node, service, hints, &ai); int error = getaddrinfo(node, service, hints, &ai);
if (error != 0) if (error != 0) {
throw FormatRuntimeError("Failed to resolve '%s':'%s': %s", #ifdef _WIN32
const char *msg = gai_strerrorA(error);
#else
const char *msg = gai_strerror(error);
#endif
throw FmtRuntimeError("Failed to resolve '{}':'{}': {}",
node == nullptr ? "" : node, node == nullptr ? "" : node,
service == nullptr ? "" : service, service == nullptr ? "" : service,
gai_strerror(error)); msg);
}
return AddressInfoList(ai); return AddressInfoList(ai);
} }
@ -89,7 +95,7 @@ FindAndResolveInterfaceName(char *host, size_t size)
const unsigned i = if_nametoindex(interface); const unsigned i = if_nametoindex(interface);
if (i == 0) if (i == 0)
throw FormatRuntimeError("No such interface: %s", interface); throw FmtRuntimeError("No such interface: {}", interface);
sprintf(interface, "%u", i); sprintf(interface, "%u", i);
} }

View File

@ -49,6 +49,9 @@ net = static_library(
'SocketDescriptor.cxx', 'SocketDescriptor.cxx',
'SocketError.cxx', 'SocketError.cxx',
include_directories: inc, include_directories: inc,
dependencies: [
fmt_dep,
],
) )
net_dep = declare_dependency( net_dep = declare_dependency(

View File

@ -22,10 +22,10 @@
#include "Domain.hxx" #include "Domain.hxx"
#include "lib/fmt/AudioFormatFormatter.hxx" #include "lib/fmt/AudioFormatFormatter.hxx"
#include "lib/fmt/ExceptionFormatter.hxx" #include "lib/fmt/ExceptionFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "mixer/Mixer.hxx" #include "mixer/Mixer.hxx"
#include "mixer/plugins/SoftwareMixerPlugin.hxx" #include "mixer/plugins/SoftwareMixerPlugin.hxx"
#include "filter/plugins/ConvertFilterPlugin.hxx" #include "filter/plugins/ConvertFilterPlugin.hxx"
#include "util/RuntimeError.hxx"
#include "util/StringBuffer.hxx" #include "util/StringBuffer.hxx"
#include "Log.hxx" #include "Log.hxx"
@ -59,7 +59,7 @@ FilteredAudioOutput::Enable()
try { try {
output->Enable(); output->Enable();
} catch (...) { } catch (...) {
std::throw_with_nested(FormatRuntimeError("Failed to enable output %s", std::throw_with_nested(FmtRuntimeError("Failed to enable output {}",
GetLogName())); GetLogName()));
} }
} }
@ -76,7 +76,7 @@ FilteredAudioOutput::ConfigureConvertFilter()
try { try {
convert_filter_set(convert_filter.Get(), out_audio_format); convert_filter_set(convert_filter.Get(), out_audio_format);
} catch (...) { } catch (...) {
std::throw_with_nested(FormatRuntimeError("Failed to convert for %s", std::throw_with_nested(FmtRuntimeError("Failed to convert for {}",
GetLogName())); GetLogName()));
} }
} }
@ -89,7 +89,7 @@ FilteredAudioOutput::OpenOutputAndConvert(AudioFormat desired_audio_format)
try { try {
output->Open(out_audio_format); output->Open(out_audio_format);
} catch (...) { } catch (...) {
std::throw_with_nested(FormatRuntimeError("Failed to open %s", std::throw_with_nested(FmtRuntimeError("Failed to open {}",
GetLogName())); GetLogName()));
} }

View File

@ -23,6 +23,7 @@
#include "OutputAPI.hxx" #include "OutputAPI.hxx"
#include "Defaults.hxx" #include "Defaults.hxx"
#include "lib/fmt/ExceptionFormatter.hxx" #include "lib/fmt/ExceptionFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "pcm/AudioParser.hxx" #include "pcm/AudioParser.hxx"
#include "mixer/Type.hxx" #include "mixer/Type.hxx"
#include "mixer/Control.hxx" #include "mixer/Control.hxx"
@ -36,7 +37,6 @@
#include "filter/plugins/TwoFilters.hxx" #include "filter/plugins/TwoFilters.hxx"
#include "filter/plugins/VolumeFilterPlugin.hxx" #include "filter/plugins/VolumeFilterPlugin.hxx"
#include "filter/plugins/NormalizeFilterPlugin.hxx" #include "filter/plugins/NormalizeFilterPlugin.hxx"
#include "util/RuntimeError.hxx"
#include "util/StringAPI.hxx" #include "util/StringAPI.hxx"
#include "util/StringFormat.hxx" #include "util/StringFormat.hxx"
#include "Log.hxx" #include "Log.hxx"
@ -282,7 +282,8 @@ audio_output_new(EventLoop &normal_event_loop, EventLoop &rt_event_loop,
plugin = AudioOutputPlugin_get(p); plugin = AudioOutputPlugin_get(p);
if (plugin == nullptr) if (plugin == nullptr)
throw FormatRuntimeError("No such audio output plugin: %s", p); throw FmtRuntimeError("No such audio output plugin: {}",
p);
} else { } else {
LogWarning(output_domain, LogWarning(output_domain,
"No 'audio_output' defined in config file"); "No 'audio_output' defined in config file");

View File

@ -27,7 +27,7 @@
#include "config/Block.hxx" #include "config/Block.hxx"
#include "config/Data.hxx" #include "config/Data.hxx"
#include "config/Option.hxx" #include "config/Option.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include "util/StringAPI.hxx" #include "util/StringAPI.hxx"
#include <cassert> #include <cassert>
@ -62,7 +62,7 @@ try {
mixer_listener); mixer_listener);
} catch (...) { } catch (...) {
if (block.line > 0) if (block.line > 0)
std::throw_with_nested(FormatRuntimeError("Failed to configure output in line %i", std::throw_with_nested(FmtRuntimeError("Failed to configure output in line {}",
block.line)); block.line));
else else
throw; throw;
@ -99,9 +99,9 @@ MultipleOutputs::Configure(EventLoop &event_loop, EventLoop &rt_event_loop,
client, block, defaults, client, block, defaults,
&filter_factory); &filter_factory);
if (HasName(output->GetName())) if (HasName(output->GetName()))
throw FormatRuntimeError("output devices with identical " throw FmtRuntimeError("output devices with identical "
"names: %s", "names: {}",
output->GetName().c_str()); output->GetName());
outputs.emplace_back(std::move(output)); outputs.emplace_back(std::move(output));
}); });

View File

@ -23,8 +23,9 @@
#include "filter/Prepared.hxx" #include "filter/Prepared.hxx"
#include "filter/plugins/ReplayGainFilterPlugin.hxx" #include "filter/plugins/ReplayGainFilterPlugin.hxx"
#include "pcm/Mix.hxx" #include "pcm/Mix.hxx"
#include "lib/fmt/AudioFormatFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "thread/Mutex.hxx" #include "thread/Mutex.hxx"
#include "util/RuntimeError.hxx"
#include <string.h> #include <string.h>
@ -198,8 +199,8 @@ AudioOutputSource::FilterChunk(const MusicChunk &chunk)
if (!pcm_mix(cross_fade_dither, dest, data.data(), data.size(), if (!pcm_mix(cross_fade_dither, dest, data.data(), data.size(),
in_audio_format.format, in_audio_format.format,
mix_ratio)) mix_ratio))
throw FormatRuntimeError("Cannot cross-fade format %s", throw FmtRuntimeError("Cannot cross-fade format {}",
sample_format_to_string(in_audio_format.format)); in_audio_format.format);
data = {(const std::byte *)dest, other_data.size()}; data = {(const std::byte *)dest, other_data.size()};
} }

View File

@ -24,12 +24,12 @@
#include "Domain.hxx" #include "Domain.hxx"
#include "lib/fmt/AudioFormatFormatter.hxx" #include "lib/fmt/AudioFormatFormatter.hxx"
#include "lib/fmt/ExceptionFormatter.hxx" #include "lib/fmt/ExceptionFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "thread/Util.hxx" #include "thread/Util.hxx"
#include "thread/Slack.hxx" #include "thread/Slack.hxx"
#include "thread/Name.hxx" #include "thread/Name.hxx"
#include "util/StringBuffer.hxx" #include "util/StringBuffer.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
#include "util/RuntimeError.hxx"
#include "Log.hxx" #include "Log.hxx"
#include <cassert> #include <cassert>
@ -145,7 +145,7 @@ AudioOutputControl::InternalOpen(const AudioFormat in_audio_format,
output->prepared_other_replay_gain_filter.get(), output->prepared_other_replay_gain_filter.get(),
*output->prepared_filter); *output->prepared_filter);
} catch (...) { } catch (...) {
std::throw_with_nested(FormatRuntimeError("Failed to open filter for %s", std::throw_with_nested(FmtRuntimeError("Failed to open filter for {}",
GetLogName())); GetLogName()));
} }

View File

@ -25,6 +25,7 @@
#include "lib/alsa/NonBlock.hxx" #include "lib/alsa/NonBlock.hxx"
#include "lib/alsa/PeriodBuffer.hxx" #include "lib/alsa/PeriodBuffer.hxx"
#include "lib/alsa/Version.hxx" #include "lib/alsa/Version.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "lib/fmt/ToBuffer.hxx" #include "lib/fmt/ToBuffer.hxx"
#include "../OutputAPI.hxx" #include "../OutputAPI.hxx"
#include "../Error.hxx" #include "../Error.hxx"
@ -34,7 +35,6 @@
#include "thread/Mutex.hxx" #include "thread/Mutex.hxx"
#include "thread/Cond.hxx" #include "thread/Cond.hxx"
#include "util/Manual.hxx" #include "util/Manual.hxx"
#include "util/RuntimeError.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "event/MultiSocketMonitor.hxx" #include "event/MultiSocketMonitor.hxx"
#include "event/InjectEvent.hxx" #include "event/InjectEvent.hxx"
@ -846,7 +846,7 @@ AlsaOutput::Open(AudioFormat &audio_format)
); );
} catch (...) { } catch (...) {
snd_pcm_close(pcm); snd_pcm_close(pcm);
std::throw_with_nested(FormatRuntimeError("Error opening ALSA device \"%s\"", std::throw_with_nested(FmtRuntimeError("Error opening ALSA device \"{}\"",
GetDevice())); GetDevice()));
} }

View File

@ -19,10 +19,10 @@
#include "AoOutputPlugin.hxx" #include "AoOutputPlugin.hxx"
#include "../OutputAPI.hxx" #include "../OutputAPI.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "thread/SafeSingleton.hxx" #include "thread/SafeSingleton.hxx"
#include "system/Error.hxx" #include "system/Error.hxx"
#include "util/IterableSplitString.hxx" #include "util/IterableSplitString.hxx"
#include "util/RuntimeError.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/StringAPI.hxx" #include "util/StringAPI.hxx"
#include "util/StringSplit.hxx" #include "util/StringSplit.hxx"
@ -121,7 +121,7 @@ AoOutput::AoOutput(const ConfigBlock &block)
driver = ao_driver_id(value); driver = ao_driver_id(value);
if (driver < 0) if (driver < 0)
throw FormatRuntimeError("\"%s\" is not a valid ao driver", throw FmtRuntimeError("\"{}\" is not a valid ao driver",
value); value);
ao_info *ai = ao_driver_info(driver); ao_info *ai = ao_driver_info(driver);
@ -136,8 +136,8 @@ AoOutput::AoOutput(const ConfigBlock &block)
for (const std::string_view i : IterableSplitString(value, ';')) { for (const std::string_view i : IterableSplitString(value, ';')) {
const auto [n, v] = Split(Strip(i), '='); const auto [n, v] = Split(Strip(i), '=');
if (n.empty() || v.data() == nullptr) if (n.empty() || v.data() == nullptr)
throw FormatRuntimeError("problems parsing option \"%.*s\"", throw FmtRuntimeError("problems parsing option \"{}\"",
int(i.size()), i.data()); i);
ao_append_option(&options, std::string{n}.c_str(), ao_append_option(&options, std::string{n}.c_str(),
std::string{v}.c_str()); std::string{v}.c_str());

View File

@ -21,12 +21,12 @@
#include "../OutputAPI.hxx" #include "../OutputAPI.hxx"
#include "../Timer.hxx" #include "../Timer.hxx"
#include "lib/fmt/PathFormatter.hxx" #include "lib/fmt/PathFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "fs/FileInfo.hxx" #include "fs/FileInfo.hxx"
#include "lib/fmt/SystemError.hxx" #include "lib/fmt/SystemError.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/RuntimeError.hxx"
#include "Log.hxx" #include "Log.hxx"
#include "open.h" #include "open.h"
@ -37,7 +37,6 @@
class FifoOutput final : AudioOutput { class FifoOutput final : AudioOutput {
const AllocatedPath path; const AllocatedPath path;
std::string path_utf8;
int input = -1; int input = -1;
int output = -1; int output = -1;
@ -84,8 +83,6 @@ FifoOutput::FifoOutput(const ConfigBlock &block)
if (path.IsNull()) if (path.IsNull())
throw std::runtime_error("No \"path\" parameter specified"); throw std::runtime_error("No \"path\" parameter specified");
path_utf8 = path.ToUTF8();
OpenFifo(); OpenFifo();
} }
@ -147,8 +144,8 @@ FifoOutput::Check()
} }
if (!S_ISFIFO(st.st_mode)) if (!S_ISFIFO(st.st_mode))
throw FormatRuntimeError("\"%s\" already exists, but is not a FIFO", throw FmtRuntimeError("\"{}\" already exists, but is not a FIFO",
path_utf8.c_str()); path);
} }
inline void inline void

View File

@ -22,10 +22,10 @@
#include "../OutputAPI.hxx" #include "../OutputAPI.hxx"
#include "../Error.hxx" #include "../Error.hxx"
#include "output/Features.h" #include "output/Features.h"
#include "lib/fmt/RuntimeError.hxx"
#include "thread/Mutex.hxx" #include "thread/Mutex.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
#include "util/IterableSplitString.hxx" #include "util/IterableSplitString.hxx"
#include "util/RuntimeError.hxx"
#include "util/SpanCast.hxx" #include "util/SpanCast.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx" #include "Log.hxx"
@ -123,7 +123,7 @@ private:
void Shutdown(const char *reason) noexcept { void Shutdown(const char *reason) noexcept {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
error = std::make_exception_ptr(FormatRuntimeError("JACK connection shutdown: %s", error = std::make_exception_ptr(FmtRuntimeError("JACK connection shutdown: {}",
reason)); reason));
} }
@ -416,8 +416,8 @@ JackOutput::Connect()
jack_status_t status; jack_status_t status;
client = jack_client_open(name, options, &status, server_name); client = jack_client_open(name, options, &status, server_name);
if (client == nullptr) if (client == nullptr)
throw FormatRuntimeError("Failed to connect to JACK server, status=%d", throw FmtRuntimeError("Failed to connect to JACK server, status={}",
status); (unsigned)status);
jack_set_process_callback(client, Process, this); jack_set_process_callback(client, Process, this);
jack_on_info_shutdown(client, OnShutdown, this); jack_on_info_shutdown(client, OnShutdown, this);
@ -430,8 +430,8 @@ JackOutput::Connect()
portflags, 0); portflags, 0);
if (ports[i] == nullptr) { if (ports[i] == nullptr) {
Disconnect(); Disconnect();
throw FormatRuntimeError("Cannot register output port \"%s\"", throw FmtRuntimeError("Cannot register output port \"{}\"",
source_ports[i].c_str()); source_ports[i]);
} }
} }
} }
@ -590,7 +590,7 @@ JackOutput::Start()
dports[i]); dports[i]);
if (ret != 0) { if (ret != 0) {
Stop(); Stop();
throw FormatRuntimeError("Not a valid JACK port: %s", throw FmtRuntimeError("Not a valid JACK port: {}",
dports[i]); dports[i]);
} }
} }
@ -604,7 +604,7 @@ JackOutput::Start()
duplicate_port); duplicate_port);
if (ret != 0) { if (ret != 0) {
Stop(); Stop();
throw FormatRuntimeError("Not a valid JACK port: %s", throw FmtRuntimeError("Not a valid JACK port: {}",
duplicate_port); duplicate_port);
} }
} }

View File

@ -25,7 +25,7 @@
#include "apple/Throw.hxx" #include "apple/Throw.hxx"
#include "../OutputAPI.hxx" #include "../OutputAPI.hxx"
#include "mixer/plugins/OSXMixerPlugin.hxx" #include "mixer/plugins/OSXMixerPlugin.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/Manual.hxx" #include "util/Manual.hxx"
#include "pcm/Export.hxx" #include "pcm/Export.hxx"
@ -247,7 +247,7 @@ osx_output_parse_channel_map(const char *device_name,
while (*channel_map_str) { while (*channel_map_str) {
if (inserted_channels >= num_channels) if (inserted_channels >= num_channels)
throw FormatRuntimeError("%s: channel map contains more than %u entries or trailing garbage", throw FmtRuntimeError("{}: channel map contains more than {} entries or trailing garbage",
device_name, num_channels); device_name, num_channels);
if (!want_number && *channel_map_str == ',') { if (!want_number && *channel_map_str == ',') {
@ -262,7 +262,7 @@ osx_output_parse_channel_map(const char *device_name,
char *endptr; char *endptr;
channel_map[inserted_channels] = strtol(channel_map_str, &endptr, 10); channel_map[inserted_channels] = strtol(channel_map_str, &endptr, 10);
if (channel_map[inserted_channels] < -1) if (channel_map[inserted_channels] < -1)
throw FormatRuntimeError("%s: channel map value %d not allowed (must be -1 or greater)", throw FmtRuntimeError("{}: channel map value {} not allowed (must be -1 or greater)",
device_name, channel_map[inserted_channels]); device_name, channel_map[inserted_channels]);
channel_map_str = endptr; channel_map_str = endptr;
@ -275,12 +275,12 @@ osx_output_parse_channel_map(const char *device_name,
continue; continue;
} }
throw FormatRuntimeError("%s: invalid character '%c' in channel map", throw FmtRuntimeError("{}: invalid character '{}' in channel map",
device_name, *channel_map_str); device_name, *channel_map_str);
} }
if (inserted_channels < num_channels) if (inserted_channels < num_channels)
throw FormatRuntimeError("%s: channel map contains less than %u entries", throw FmtRuntimeError("{}: channel map contains less than {} entries",
device_name, num_channels); device_name, num_channels);
} }
@ -453,7 +453,7 @@ osx_output_set_device_format(AudioDeviceID dev_id,
sizeof(output_format), sizeof(output_format),
&output_format); &output_format);
if (err != noErr) if (err != noErr)
throw FormatRuntimeError("Failed to change the stream format: %d", throw FmtRuntimeError("Failed to change the stream format: {}",
err); err);
} }
@ -582,8 +582,7 @@ FindAudioDeviceByName(const char *name)
return id; return id;
} }
throw FormatRuntimeError("Found no audio device with name '%s' ", throw FmtRuntimeError("Found no audio device names '{}'", name);
name);
} }
static void static void

View File

@ -19,7 +19,7 @@
#include "OpenALOutputPlugin.hxx" #include "OpenALOutputPlugin.hxx"
#include "../OutputAPI.hxx" #include "../OutputAPI.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include <unistd.h> #include <unistd.h>
@ -126,13 +126,13 @@ OpenALOutput::SetupContext()
{ {
device = alcOpenDevice(device_name); device = alcOpenDevice(device_name);
if (device == nullptr) if (device == nullptr)
throw FormatRuntimeError("Error opening OpenAL device \"%s\"", throw FmtRuntimeError("Error opening OpenAL device \"{}\"",
device_name); device_name);
context = alcCreateContext(device, nullptr); context = alcCreateContext(device, nullptr);
if (context == nullptr) { if (context == nullptr) {
alcCloseDevice(device); alcCloseDevice(device);
throw FormatRuntimeError("Error creating context for \"%s\"", throw FmtRuntimeError("Error creating context for \"{}\"",
device_name); device_name);
} }
} }

View File

@ -21,7 +21,7 @@
#include "../OutputAPI.hxx" #include "../OutputAPI.hxx"
#include "encoder/EncoderInterface.hxx" #include "encoder/EncoderInterface.hxx"
#include "encoder/Configured.hxx" #include "encoder/Configured.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
#include "util/StringAPI.hxx" #include "util/StringAPI.hxx"
@ -105,8 +105,8 @@ require_block_string(const ConfigBlock &block, const char *name)
{ {
const char *value = block.GetBlockValue(name); const char *value = block.GetBlockValue(name);
if (value == nullptr) if (value == nullptr)
throw FormatRuntimeError("no \"%s\" defined for shout device defined " throw FmtRuntimeError("no \"{}\" defined for shout device defined "
"at line %d\n", name, block.line); "at line {}\n", name, block.line);
return value; return value;
} }
@ -140,7 +140,7 @@ ParseShoutTls(const char *value)
else if (StringIsEqual(value, "rfc2817")) else if (StringIsEqual(value, "rfc2817"))
return SHOUT_TLS_RFC2817; return SHOUT_TLS_RFC2817;
else else
throw FormatRuntimeError("invalid shout TLS option \"%s\"", throw FmtRuntimeError("invalid shout TLS option \"{}\"",
value); value);
} }
@ -163,7 +163,7 @@ ParseShoutProtocol(const char *value, const char *mime_type)
if (StringIsEqual(value, "shoutcast")) { if (StringIsEqual(value, "shoutcast")) {
if (!StringIsEqual(mime_type, "audio/mpeg")) if (!StringIsEqual(mime_type, "audio/mpeg"))
throw FormatRuntimeError("you cannot stream \"%s\" to shoutcast, use mp3", throw FmtRuntimeError("you cannot stream \"{}\" to shoutcast, use mp3",
mime_type); mime_type);
return SHOUT_PROTOCOL_ICY; return SHOUT_PROTOCOL_ICY;
} else if (StringIsEqual(value, "icecast1")) } else if (StringIsEqual(value, "icecast1"))
@ -171,7 +171,7 @@ ParseShoutProtocol(const char *value, const char *mime_type)
else if (StringIsEqual(value, "icecast2")) else if (StringIsEqual(value, "icecast2"))
return SHOUT_PROTOCOL_HTTP; return SHOUT_PROTOCOL_HTTP;
else else
throw FormatRuntimeError("shout protocol \"%s\" is not \"shoutcast\" or " throw FmtRuntimeError("shout protocol \"{}\" is not \"shoutcast\" or "
"\"icecast1\"or \"icecast2\"", "\"icecast1\"or \"icecast2\"",
value); value);
} }
@ -309,13 +309,13 @@ HandleShoutError(shout_t *shout_conn, int err)
case SHOUTERR_UNCONNECTED: case SHOUTERR_UNCONNECTED:
case SHOUTERR_SOCKET: case SHOUTERR_SOCKET:
throw FormatRuntimeError("Lost shout connection to %s:%i: %s", throw FmtRuntimeError("Lost shout connection to {}:{}: {}",
shout_get_host(shout_conn), shout_get_host(shout_conn),
shout_get_port(shout_conn), shout_get_port(shout_conn),
shout_get_error(shout_conn)); shout_get_error(shout_conn));
default: default:
throw FormatRuntimeError("connection to %s:%i error: %s", throw FmtRuntimeError("connection to {}:{} error: {}",
shout_get_host(shout_conn), shout_get_host(shout_conn),
shout_get_port(shout_conn), shout_get_port(shout_conn),
shout_get_error(shout_conn)); shout_get_error(shout_conn));
@ -381,7 +381,7 @@ ShoutOpen(shout_t *shout_conn)
break; break;
default: default:
throw FormatRuntimeError("problem opening connection to shout server %s:%i: %s", throw FmtRuntimeError("problem opening connection to shout server {}:{}: {}",
shout_get_host(shout_conn), shout_get_host(shout_conn),
shout_get_port(shout_conn), shout_get_port(shout_conn),
shout_get_error(shout_conn)); shout_get_error(shout_conn));

View File

@ -21,8 +21,8 @@
#include "../OutputAPI.hxx" #include "../OutputAPI.hxx"
#include "pcm/Buffer.hxx" #include "pcm/Buffer.hxx"
#include "mixer/plugins/WinmmMixerPlugin.hxx" #include "mixer/plugins/WinmmMixerPlugin.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "util/RuntimeError.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
#include <array> #include <array>
@ -91,7 +91,7 @@ MakeWaveOutError(MMRESULT result, const char *prefix)
char buffer[256]; char buffer[256];
if (waveOutGetErrorTextA(result, buffer, if (waveOutGetErrorTextA(result, buffer,
std::size(buffer)) == MMSYSERR_NOERROR) std::size(buffer)) == MMSYSERR_NOERROR)
return FormatRuntimeError("%s: %s", prefix, buffer); return FmtRuntimeError("{}: {}", prefix, buffer);
else else
return std::runtime_error(prefix); return std::runtime_error(prefix);
} }
@ -122,7 +122,7 @@ get_device_id(const char *device_name)
UINT id = strtoul(device_name, &endptr, 0); UINT id = strtoul(device_name, &endptr, 0);
if (endptr > device_name && *endptr == 0) { if (endptr > device_name && *endptr == 0) {
if (id >= numdevs) if (id >= numdevs)
throw FormatRuntimeError("device \"%s\" is not found", throw FmtRuntimeError("device \"{}\" is not found",
device_name); device_name);
return id; return id;
@ -143,7 +143,7 @@ get_device_id(const char *device_name)
return i; return i;
} }
throw FormatRuntimeError("device \"%s\" is not found", device_name); throw FmtRuntimeError("device \"{}\" is not found", device_name);
} }
WinmmOutput::WinmmOutput(const ConfigBlock &block) WinmmOutput::WinmmOutput(const ConfigBlock &block)

View File

@ -27,6 +27,7 @@
#include "output/OutputAPI.hxx" #include "output/OutputAPI.hxx"
#include "lib/icu/Win32.hxx" #include "lib/icu/Win32.hxx"
#include "lib/fmt/AudioFormatFormatter.hxx" #include "lib/fmt/AudioFormatFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "mixer/plugins/WasapiMixerPlugin.hxx" #include "mixer/plugins/WasapiMixerPlugin.hxx"
#include "output/Error.hxx" #include "output/Error.hxx"
#include "pcm/Export.hxx" #include "pcm/Export.hxx"
@ -36,7 +37,6 @@
#include "thread/Thread.hxx" #include "thread/Thread.hxx"
#include "util/AllocatedString.hxx" #include "util/AllocatedString.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/RuntimeError.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
#include "util/StringBuffer.hxx" #include "util/StringBuffer.hxx"
#include "win32/Com.hxx" #include "win32/Com.hxx"
@ -806,8 +806,8 @@ WasapiOutput::ChooseDevice()
if (!SafeSilenceTry([this, &id]() { id = std::stoul(device_config); })) { if (!SafeSilenceTry([this, &id]() { id = std::stoul(device_config); })) {
device = SearchDevice(*enumerator, device_config); device = SearchDevice(*enumerator, device_config);
if (!device) if (!device)
throw FormatRuntimeError("Device '%s' not found", throw FmtRuntimeError("Device '{}' not found",
device_config.c_str()); device_config);
} else } else
device = GetDevice(*enumerator, id); device = GetDevice(*enumerator, id);
} else { } else {

View File

@ -24,7 +24,7 @@
#include "AudioParser.hxx" #include "AudioParser.hxx"
#include "AudioFormat.hxx" #include "AudioFormat.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include <cassert> #include <cassert>
@ -46,7 +46,7 @@ ParseSampleRate(const char *src, bool mask, const char **endptr_r)
if (endptr == src) { if (endptr == src) {
throw std::invalid_argument("Failed to parse the sample rate"); throw std::invalid_argument("Failed to parse the sample rate");
} else if (!audio_valid_sample_rate(value)) } else if (!audio_valid_sample_rate(value))
throw FormatInvalidArgument("Invalid sample rate: %lu", value); throw FmtInvalidArgument("Invalid sample rate: {}", value);
*endptr_r = endptr; *endptr_r = endptr;
return value; return value;
@ -100,8 +100,7 @@ ParseSampleFormat(const char *src, bool mask, const char **endptr_r)
break; break;
default: default:
throw FormatInvalidArgument("Invalid sample format: %lu", throw FmtInvalidArgument("Invalid sample format: {}", value);
value);
} }
assert(audio_valid_sample_format(sample_format)); assert(audio_valid_sample_format(sample_format));
@ -125,8 +124,7 @@ ParseChannelCount(const char *src, bool mask, const char **endptr_r)
if (endptr == src) if (endptr == src)
throw std::invalid_argument("Failed to parse the channel count"); throw std::invalid_argument("Failed to parse the channel count");
else if (!audio_valid_channel_count(value)) else if (!audio_valid_channel_count(value))
throw FormatInvalidArgument("Invalid channel count: %u", throw FmtInvalidArgument("Invalid channel count: {}", value);
value);
*endptr_r = endptr; *endptr_r = endptr;
return value; return value;
@ -152,7 +150,7 @@ ParseAudioFormat(const char *src, bool mask)
src = endptr + 1; src = endptr + 1;
dest.channels = ParseChannelCount(src, mask, &src); dest.channels = ParseChannelCount(src, mask, &src);
if (*src != 0) if (*src != 0)
throw FormatInvalidArgument("Extra data after channel count: %s", throw FmtInvalidArgument("Extra data after channel count: {}",
src); src);
return dest; return dest;
@ -178,7 +176,7 @@ ParseAudioFormat(const char *src, bool mask)
dest.channels = ParseChannelCount(src, mask, &src); dest.channels = ParseChannelCount(src, mask, &src);
if (*src != 0) if (*src != 0)
throw FormatInvalidArgument("Extra data after channel count: %s", throw FmtInvalidArgument("Extra data after channel count: {}",
src); src);
assert(mask assert(mask

View File

@ -19,7 +19,8 @@
#include "ChannelsConverter.hxx" #include "ChannelsConverter.hxx"
#include "PcmChannels.hxx" #include "PcmChannels.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/AudioFormatFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/SpanCast.hxx" #include "util/SpanCast.hxx"
#include <cassert> #include <cassert>
@ -38,8 +39,8 @@ PcmChannelsConverter::Open(SampleFormat _format,
break; break;
default: default:
throw FormatRuntimeError("PCM channel conversion for %s is not implemented", throw FmtRuntimeError("PCM channel conversion for {} is not implemented",
sample_format_to_string(_format)); _format);
} }
format = _format; format = _format;

View File

@ -19,13 +19,13 @@
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "AudioFormat.hxx" #include "AudioFormat.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
void void
CheckSampleRate(unsigned long sample_rate) CheckSampleRate(unsigned long sample_rate)
{ {
if (!audio_valid_sample_rate(sample_rate)) if (!audio_valid_sample_rate(sample_rate))
throw FormatRuntimeError("Invalid sample rate: %lu", throw FmtRuntimeError("Invalid sample rate: {}",
sample_rate); sample_rate);
} }
@ -33,7 +33,7 @@ void
CheckSampleFormat(SampleFormat sample_format) CheckSampleFormat(SampleFormat sample_format)
{ {
if (!audio_valid_sample_format(sample_format)) if (!audio_valid_sample_format(sample_format))
throw FormatRuntimeError("Invalid sample format: %u", throw FmtRuntimeError("Invalid sample format: {}",
unsigned(sample_format)); unsigned(sample_format));
} }
@ -41,7 +41,7 @@ void
CheckChannelCount(unsigned channels) CheckChannelCount(unsigned channels)
{ {
if (!audio_valid_channel_count(channels)) if (!audio_valid_channel_count(channels))
throw FormatRuntimeError("Invalid channel count: %u", throw FmtRuntimeError("Invalid channel count: {}",
channels); channels);
} }

View File

@ -23,7 +23,7 @@
#include "config/Option.hxx" #include "config/Option.hxx"
#include "config/Block.hxx" #include "config/Block.hxx"
#include "config/Param.hxx" #include "config/Param.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include "config.h" #include "config.h"
#ifdef ENABLE_LIBSAMPLERATE #ifdef ENABLE_LIBSAMPLERATE
@ -122,7 +122,7 @@ GetResamplerConfig(const ConfigData &config, ConfigBlock &buffer)
return MigrateResamplerConfig(old_param, buffer); return MigrateResamplerConfig(old_param, buffer);
if (old_param != nullptr) if (old_param != nullptr)
throw FormatRuntimeError("Cannot use both 'resampler' (line %d) and 'samplerate_converter' (line %d)", throw FmtRuntimeError("Cannot use both 'resampler' (line {}) and 'samplerate_converter' (line {})",
block->line, old_param->line); block->line, old_param->line);
block->SetUsed(); block->SetUsed();
@ -137,7 +137,7 @@ pcm_resampler_global_init(const ConfigData &config)
const char *plugin_name = block->GetBlockValue("plugin"); const char *plugin_name = block->GetBlockValue("plugin");
if (plugin_name == nullptr) if (plugin_name == nullptr)
throw FormatRuntimeError("'plugin' missing in line %d", throw FmtRuntimeError("'plugin' missing in line {}",
block->line); block->line);
if (strcmp(plugin_name, "internal") == 0) { if (strcmp(plugin_name, "internal") == 0) {
@ -153,7 +153,7 @@ pcm_resampler_global_init(const ConfigData &config)
pcm_resample_lsr_global_init(*block); pcm_resample_lsr_global_init(*block);
#endif #endif
} else { } else {
throw FormatRuntimeError("No such resampler plugin: %s", throw FmtRuntimeError("No such resampler plugin: {}",
plugin_name); plugin_name);
} }
} }

View File

@ -19,7 +19,8 @@
#include "FormatConverter.hxx" #include "FormatConverter.hxx"
#include "PcmFormat.hxx" #include "PcmFormat.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/AudioFormatFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include <cassert> #include <cassert>
@ -36,9 +37,8 @@ PcmFormatConverter::Open(SampleFormat _src_format, SampleFormat _dest_format)
case SampleFormat::S8: case SampleFormat::S8:
case SampleFormat::DSD: case SampleFormat::DSD:
throw FormatRuntimeError("PCM conversion from %s to %s is not implemented", throw FmtRuntimeError("PCM conversion from {} to {} is not implemented",
sample_format_to_string(_src_format), _src_format, _dest_format);
sample_format_to_string(_dest_format));
case SampleFormat::S16: case SampleFormat::S16:
case SampleFormat::S24_P32: case SampleFormat::S24_P32:

View File

@ -19,8 +19,8 @@
#include "LibsamplerateResampler.hxx" #include "LibsamplerateResampler.hxx"
#include "config/Block.hxx" #include "config/Block.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/ASCII.hxx" #include "util/ASCII.hxx"
#include "util/RuntimeError.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/SpanCast.hxx" #include "util/SpanCast.hxx"
#include "Log.hxx" #include "Log.hxx"
@ -69,7 +69,7 @@ pcm_resample_lsr_global_init(const ConfigBlock &block)
{ {
const char *converter = block.GetBlockValue("type", "2"); const char *converter = block.GetBlockValue("type", "2");
if (!lsr_parse_converter(converter)) if (!lsr_parse_converter(converter))
throw FormatRuntimeError("unknown samplerate converter '%s'", throw FmtRuntimeError("unknown samplerate converter '{}'",
converter); converter);
FmtDebug(libsamplerate_domain, FmtDebug(libsamplerate_domain,
@ -93,7 +93,7 @@ LibsampleratePcmResampler::Open(AudioFormat &af, unsigned new_sample_rate)
int src_error; int src_error;
state = src_new(lsr_converter, channels, &src_error); state = src_new(lsr_converter, channels, &src_error);
if (!state) if (!state)
throw FormatRuntimeError("libsamplerate initialization has failed: %s", throw FmtRuntimeError("libsamplerate initialization has failed: {}",
src_strerror(src_error)); src_strerror(src_error));
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
@ -138,7 +138,7 @@ LibsampleratePcmResampler::Resample2(std::span<const float> src)
int result = src_process(state, &data); int result = src_process(state, &data);
if (result != 0) if (result != 0)
throw FormatRuntimeError("libsamplerate has failed: %s", throw FmtRuntimeError("libsamplerate has failed: {}",
src_strerror(result)); src_strerror(result));
return {data.data_out, size_t(data.output_frames_gen * channels)}; return {data.data_out, size_t(data.output_frames_gen * channels)};

View File

@ -20,7 +20,7 @@
#include "SoxrResampler.hxx" #include "SoxrResampler.hxx"
#include "AudioFormat.hxx" #include "AudioFormat.hxx"
#include "config/Block.hxx" #include "config/Block.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx" #include "Log.hxx"
@ -100,18 +100,17 @@ SoxrParsePrecision(unsigned value) {
case 32: case 32:
break; break;
default: default:
throw FormatInvalidArgument( throw FmtInvalidArgument("soxr converter invalid precision: {} [16|20|24|28|32]",
"soxr converter invalid precision : %d [16|20|24|28|32]", value); value);
} }
return value; return value;
} }
static double static double
SoxrParsePhaseResponse(unsigned value) { SoxrParsePhaseResponse(unsigned value) {
if (value > 100) { if (value > 100)
throw FormatInvalidArgument( throw FmtInvalidArgument("soxr converter invalid phase_respons : {} (0-100)",
"soxr converter invalid phase_respons : %d (0-100)", value); value);
}
return double(value); return double(value);
} }
@ -120,15 +119,13 @@ static double
SoxrParsePassbandEnd(const char *svalue) { SoxrParsePassbandEnd(const char *svalue) {
char *endptr; char *endptr;
double value = strtod(svalue, &endptr); double value = strtod(svalue, &endptr);
if (svalue == endptr || *endptr != 0) { if (svalue == endptr || *endptr != 0)
throw FormatInvalidArgument( throw FmtInvalidArgument("soxr converter passband_end value not a number: {}",
"soxr converter passband_end value not a number: %s", svalue); svalue);
}
if (value < 1 || value > 100) { if (value < 1 || value > 100)
throw FormatInvalidArgument( throw FmtInvalidArgument("soxr converter invalid passband_end: {} (1-100%)",
"soxr converter invalid passband_end : %s (1-100%%)", svalue); svalue);
}
return value / 100.0; return value / 100.0;
} }
@ -137,15 +134,13 @@ static double
SoxrParseStopbandBegin(const char *svalue) { SoxrParseStopbandBegin(const char *svalue) {
char *endptr; char *endptr;
double value = strtod(svalue, &endptr); double value = strtod(svalue, &endptr);
if (svalue == endptr || *endptr != 0) { if (svalue == endptr || *endptr != 0)
throw FormatInvalidArgument( throw FmtInvalidArgument("soxr converter stopband_begin value not a number: {}",
"soxr converter stopband_begin value not a number: %s", svalue); svalue);
}
if (value < 100 || value > 199) { if (value < 100 || value > 199)
throw FormatInvalidArgument( throw FmtInvalidArgument("soxr converter invalid stopband_begin: {} (100-150%)",
"soxr converter invalid stopband_begin : %s (100-150%%)", svalue); svalue);
}
return value / 100.0; return value / 100.0;
} }
@ -155,14 +150,13 @@ SoxrParseAttenuation(const char *svalue) {
char *endptr; char *endptr;
double value = strtod(svalue, &endptr); double value = strtod(svalue, &endptr);
if (svalue == endptr || *endptr != 0) { if (svalue == endptr || *endptr != 0) {
throw FormatInvalidArgument( throw FmtInvalidArgument("soxr converter attenuation value not a number: {}",
"soxr converter attenuation value not a number: %s", svalue); svalue);
} }
if (value < 0 || value > 30) { if (value < 0 || value > 30)
throw FormatInvalidArgument( throw FmtInvalidArgument("soxr converter invalid attenuation: {} (0-30dB))",
"soxr converter invalid attenuation : %s (0-30dB))", svalue); svalue);
}
return 1 / std::pow(10, value / 10.0); return 1 / std::pow(10, value / 10.0);
} }
@ -176,7 +170,7 @@ pcm_resample_soxr_global_init(const ConfigBlock &block)
if (recipe == SOXR_INVALID_RECIPE) { if (recipe == SOXR_INVALID_RECIPE) {
assert(quality_string != nullptr); assert(quality_string != nullptr);
throw FormatRuntimeError("unknown quality setting '%s' in line %d", throw FmtRuntimeError("unknown quality setting '{}' in line {}",
quality_string, block.line); quality_string, block.line);
} else if (recipe == SOXR_CUSTOM_RECIPE) { } else if (recipe == SOXR_CUSTOM_RECIPE) {
// used to preset possible internal flags, like SOXR_RESET_ON_CLEAR // used to preset possible internal flags, like SOXR_RESET_ON_CLEAR
@ -222,7 +216,7 @@ SoxrPcmResampler::Open(AudioFormat &af, unsigned new_sample_rate)
af.channels, &e, af.channels, &e,
p_soxr_io, &soxr_quality, &soxr_runtime); p_soxr_io, &soxr_quality, &soxr_runtime);
if (soxr == nullptr) if (soxr == nullptr)
throw FormatRuntimeError("soxr initialization has failed: %s", throw FmtRuntimeError("soxr initialization has failed: {}",
e); e);
FmtDebug(soxr_domain, "soxr engine '{}'", soxr_engine(soxr)); FmtDebug(soxr_domain, "soxr engine '{}'", soxr_engine(soxr));
@ -284,7 +278,7 @@ SoxrPcmResampler::Resample(std::span<const std::byte> src)
soxr_error_t e = soxr_process(soxr, src.data(), n_frames, &i_done, soxr_error_t e = soxr_process(soxr, src.data(), n_frames, &i_done,
output_buffer, o_frames, &o_done); output_buffer, o_frames, &o_done);
if (e != nullptr) if (e != nullptr)
throw FormatRuntimeError("soxr error: %s", e); throw FmtRuntimeError("soxr error: {}", e);
return { (const std::byte *)output_buffer, o_done * frame_size }; return { (const std::byte *)output_buffer, o_done * frame_size };
} }
@ -301,7 +295,7 @@ SoxrPcmResampler::Flush()
soxr_error_t e = soxr_process(soxr, nullptr, 0, nullptr, soxr_error_t e = soxr_process(soxr, nullptr, 0, nullptr,
output_buffer, o_frames, &o_done); output_buffer, o_frames, &o_done);
if (e != nullptr) if (e != nullptr)
throw FormatRuntimeError("soxr error: %s", e); throw FmtRuntimeError("soxr error: {}", e);
if (o_done == 0) if (o_done == 0)
/* flush complete */ /* flush complete */

View File

@ -20,7 +20,8 @@
#include "Volume.hxx" #include "Volume.hxx"
#include "Silence.hxx" #include "Silence.hxx"
#include "Traits.hxx" #include "Traits.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/AudioFormatFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/TransformN.hxx" #include "util/TransformN.hxx"
#include "Dither.cxx" // including the .cxx file to get inlined templates #include "Dither.cxx" // including the .cxx file to get inlined templates
@ -154,8 +155,8 @@ PcmVolume::Open(SampleFormat _format, bool allow_convert)
switch (_format) { switch (_format) {
case SampleFormat::UNDEFINED: case SampleFormat::UNDEFINED:
throw FormatRuntimeError("Software volume for %s is not implemented", throw FmtRuntimeError("Software volume for {} is not implemented",
sample_format_to_string(_format)); _format);
case SampleFormat::S8: case SampleFormat::S8:
break; break;

View File

@ -30,6 +30,7 @@ pcm_basic = static_library(
include_directories: inc, include_directories: inc,
dependencies: [ dependencies: [
util_dep, util_dep,
fmt_dep,
], ],
) )

View File

@ -28,9 +28,9 @@
#include "../MemorySongEnumerator.hxx" #include "../MemorySongEnumerator.hxx"
#include "lib/xiph/FlacMetadataChain.hxx" #include "lib/xiph/FlacMetadataChain.hxx"
#include "lib/xiph/FlacMetadataIterator.hxx" #include "lib/xiph/FlacMetadataIterator.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "song/DetachedSong.hxx" #include "song/DetachedSong.hxx"
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "util/RuntimeError.hxx"
#include <FLAC/metadata.h> #include <FLAC/metadata.h>
@ -67,7 +67,7 @@ flac_playlist_open_stream(InputStreamPtr &&is)
{ {
FlacMetadataChain chain; FlacMetadataChain chain;
if (!chain.Read(*is)) if (!chain.Read(*is))
throw FormatRuntimeError("Failed to read FLAC metadata: %s", throw FmtRuntimeError("Failed to read FLAC metadata: {}",
chain.GetStatusString()); chain.GetStatusString());
FlacMetadataIterator iterator((FLAC__Metadata_Chain *)chain); FlacMetadataIterator iterator((FLAC__Metadata_Chain *)chain);

View File

@ -29,8 +29,8 @@
#include "pcm/AudioParser.hxx" #include "pcm/AudioParser.hxx"
#include "tag/ParseName.hxx" #include "tag/ParseName.hxx"
#include "time/ISO8601.hxx" #include "time/ISO8601.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/CharUtil.hxx" #include "util/CharUtil.hxx"
#include "util/RuntimeError.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
#include "util/StringStrip.hxx" #include "util/StringStrip.hxx"
#include "util/ASCII.hxx" #include "util/ASCII.hxx"
@ -160,8 +160,7 @@ ExpectFilterType(const char *&s)
const auto type = locate_parse_type(name.c_str()); const auto type = locate_parse_type(name.c_str());
if (type == TAG_NUM_OF_ITEM_TYPES) if (type == TAG_NUM_OF_ITEM_TYPES)
throw FormatRuntimeError("Unknown filter type: %s", throw FmtRuntimeError("Unknown filter type: {}", name);
name.c_str());
return type; return type;
} }

View File

@ -24,7 +24,7 @@
#include "config/Data.hxx" #include "config/Data.hxx"
#include "fs/StandardDirectory.hxx" #include "fs/StandardDirectory.hxx"
#include "fs/CheckFile.hxx" #include "fs/CheckFile.hxx"
#include "util/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include "util/UriExtract.hxx" #include "util/UriExtract.hxx"
static std::unique_ptr<Storage> static std::unique_ptr<Storage>
@ -32,7 +32,7 @@ CreateConfiguredStorageUri(EventLoop &event_loop, const char *uri)
{ {
auto storage = CreateStorageURI(event_loop, uri); auto storage = CreateStorageURI(event_loop, uri);
if (storage == nullptr) if (storage == nullptr)
throw FormatRuntimeError("Unrecognized storage URI: %s", uri); throw FmtRuntimeError("Unrecognized storage URI: {}", uri);
return storage; return storage;
} }

View File

@ -30,12 +30,12 @@
#include "lib/curl/Handler.hxx" #include "lib/curl/Handler.hxx"
#include "lib/curl/Escape.hxx" #include "lib/curl/Escape.hxx"
#include "lib/expat/ExpatParser.hxx" #include "lib/expat/ExpatParser.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "fs/Traits.hxx" #include "fs/Traits.hxx"
#include "event/InjectEvent.hxx" #include "event/InjectEvent.hxx"
#include "thread/Mutex.hxx" #include "thread/Mutex.hxx"
#include "thread/Cond.hxx" #include "thread/Cond.hxx"
#include "util/ASCII.hxx" #include "util/ASCII.hxx"
#include "util/RuntimeError.hxx"
#include "util/SpanCast.hxx" #include "util/SpanCast.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
#include "util/StringFormat.hxx" #include "util/StringFormat.hxx"
@ -302,7 +302,7 @@ private:
/* virtual methods from CurlResponseHandler */ /* virtual methods from CurlResponseHandler */
void OnHeaders(unsigned status, Curl::Headers &&headers) final { void OnHeaders(unsigned status, Curl::Headers &&headers) final {
if (status != 207) if (status != 207)
throw FormatRuntimeError("Status %d from WebDAV server; expected \"207 Multi-Status\"", throw FmtRuntimeError("Status {} from WebDAV server; expected \"207 Multi-Status\"",
status); status);
if (!IsXmlContentType(headers)) if (!IsXmlContentType(headers))

View File

@ -23,6 +23,7 @@
#include "storage/StorageInterface.hxx" #include "storage/StorageInterface.hxx"
#include "storage/FileInfo.hxx" #include "storage/FileInfo.hxx"
#include "lib/fmt/ExceptionFormatter.hxx" #include "lib/fmt/ExceptionFormatter.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "lib/dbus/Glue.hxx" #include "lib/dbus/Glue.hxx"
#include "lib/dbus/AsyncRequest.hxx" #include "lib/dbus/AsyncRequest.hxx"
#include "lib/dbus/Message.hxx" #include "lib/dbus/Message.hxx"
@ -38,7 +39,6 @@
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
#include "util/RuntimeError.hxx"
#include "Log.hxx" #include "Log.hxx"
#include <stdexcept> #include <stdexcept>
@ -180,8 +180,8 @@ UdisksStorage::OnListReply(ODBus::Message reply) noexcept
}); });
if (dbus_path.empty()) if (dbus_path.empty())
throw FormatRuntimeError("No such UDisks2 object: %s", throw FmtRuntimeError("No such UDisks2 object: {}",
id.c_str()); id);
if (!mount_point.empty()) { if (!mount_point.empty()) {
/* already mounted: don't attempt to mount /* already mounted: don't attempt to mount

View File

@ -22,8 +22,8 @@
#include "ParseName.hxx" #include "ParseName.hxx"
#include "config/Data.hxx" #include "config/Data.hxx"
#include "config/Option.hxx" #include "config/Option.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/ASCII.hxx" #include "util/ASCII.hxx"
#include "util/RuntimeError.hxx"
#include "util/IterableSplitString.hxx" #include "util/IterableSplitString.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
#include "util/StringStrip.hxx" #include "util/StringStrip.hxx"
@ -59,7 +59,7 @@ TagLoadConfig(const ConfigData &config)
const auto type = tag_name_parse_i(name); const auto type = tag_name_parse_i(name);
if (type == TAG_NUM_OF_ITEM_TYPES) if (type == TAG_NUM_OF_ITEM_TYPES)
throw FormatRuntimeError("error parsing metadata item \"%s\"", throw FmtRuntimeError("error parsing metadata item \"{}\"",
name); name);
if (plus) if (plus)

View File

@ -58,6 +58,7 @@ tag = static_library(
tag_sources, tag_sources,
include_directories: inc, include_directories: inc,
dependencies: [ dependencies: [
fmt_dep,
libid3tag_dep, libid3tag_dep,
], ],
) )

Some files were not shown because too many files have changed in this diff Show More