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

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

View File

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

View File

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

View File

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

View File

@@ -18,7 +18,7 @@
*/
#include "Parser.hxx"
#include "util/RuntimeError.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/StringStrip.hxx"
#include "util/StringUtil.hxx"
@@ -36,7 +36,7 @@ ParseBool(const char *value)
if (StringArrayContainsCase(f, value))
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

View File

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

View File

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

View File

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