lib/fmt/RuntimeError: new library
Replacing FormatRuntimeError().
This commit is contained in:
@@ -22,9 +22,9 @@
|
||||
#include "Format.hxx"
|
||||
#include "lib/fmt/AudioFormatFormatter.hxx"
|
||||
#include "lib/fmt/ToBuffer.hxx"
|
||||
#include "lib/fmt/RuntimeError.hxx"
|
||||
#include "util/ByteOrder.hxx"
|
||||
#include "util/Domain.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "pcm/AudioFormat.hxx"
|
||||
#include "Log.hxx"
|
||||
#include "config.h"
|
||||
@@ -224,8 +224,8 @@ SetupHw(snd_pcm_t *pcm,
|
||||
requested_sample_rate));
|
||||
|
||||
if (output_sample_rate == 0)
|
||||
throw FormatRuntimeError("Failed to configure sample rate %u Hz",
|
||||
audio_format.sample_rate);
|
||||
throw FmtRuntimeError("Failed to configure sample rate {} Hz",
|
||||
audio_format.sample_rate);
|
||||
|
||||
if (output_sample_rate != requested_sample_rate)
|
||||
audio_format.sample_rate = params.CalcInputSampleRate(output_sample_rate);
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include "NonBlock.hxx"
|
||||
#include "Error.hxx"
|
||||
#include "event/MultiSocketMonitor.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
|
||||
Event::Duration
|
||||
AlsaNonBlockPcm::PrepareSockets(MultiSocketMonitor &m, snd_pcm_t *pcm)
|
||||
|
||||
@@ -31,12 +31,12 @@
|
||||
*/
|
||||
|
||||
#include "Error.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "lib/fmt/RuntimeError.hxx"
|
||||
|
||||
void
|
||||
ODBus::Error::Throw(const char *prefix) const
|
||||
{
|
||||
throw FormatRuntimeError("%s: %s", prefix, GetMessage());
|
||||
throw FmtRuntimeError("{}: {}", prefix, GetMessage());
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "Error.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "lib/fmt/RuntimeError.hxx"
|
||||
|
||||
extern "C" {
|
||||
#include <libavutil/error.h>
|
||||
@@ -37,5 +37,5 @@ MakeFfmpegError(int errnum, const char *prefix)
|
||||
{
|
||||
char msg[256];
|
||||
av_strerror(errnum, msg, sizeof(msg));
|
||||
return FormatRuntimeError("%s: %s", prefix, msg);
|
||||
return FmtRuntimeError("{}: {}", prefix, msg);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "ChannelLayout.hxx"
|
||||
#include "SampleFormat.hxx"
|
||||
#include "pcm/AudioFormat.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "lib/fmt/RuntimeError.hxx"
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
@@ -34,7 +34,7 @@ RequireFilterByName(const char *name)
|
||||
{
|
||||
const auto *filter = avfilter_get_by_name(name);
|
||||
if (filter == nullptr)
|
||||
throw FormatRuntimeError("No such FFmpeg filter: '%s'", name);
|
||||
throw FmtRuntimeError("No such FFmpeg filter: '{}'", name);
|
||||
|
||||
return *filter;
|
||||
}
|
||||
|
||||
45
src/lib/fmt/RuntimeError.cxx
Normal file
45
src/lib/fmt/RuntimeError.cxx
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "RuntimeError.hxx"
|
||||
#include "ToBuffer.hxx"
|
||||
|
||||
std::runtime_error
|
||||
VFmtRuntimeError(fmt::string_view format_str, fmt::format_args args) noexcept
|
||||
{
|
||||
const auto msg = VFmtBuffer<512>(format_str, args);
|
||||
return std::runtime_error{msg};
|
||||
}
|
||||
|
||||
std::invalid_argument
|
||||
VFmtInvalidArgument(fmt::string_view format_str, fmt::format_args args) noexcept
|
||||
{
|
||||
const auto msg = VFmtBuffer<512>(format_str, args);
|
||||
return std::invalid_argument{msg};
|
||||
}
|
||||
75
src/lib/fmt/RuntimeError.hxx
Normal file
75
src/lib/fmt/RuntimeError.hxx
Normal 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
|
||||
}
|
||||
@@ -10,6 +10,7 @@ endif
|
||||
|
||||
fmt = static_library(
|
||||
'fmt',
|
||||
'RuntimeError.cxx',
|
||||
'SystemError.cxx',
|
||||
include_directories: inc,
|
||||
dependencies: libfmt,
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "Collate.hxx"
|
||||
#include "Canonicalize.hxx"
|
||||
#include "Error.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
|
||||
#include <unicode/uclean.h>
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "system/Error.hxx"
|
||||
#include "lib/fmt/RuntimeError.hxx"
|
||||
|
||||
/* sorry for this horrible piece of code - there's no elegant way to
|
||||
load DLLs at runtime */
|
||||
@@ -102,7 +103,7 @@ GetFunction(HMODULE h, const char *name, T &result)
|
||||
{
|
||||
auto f = GetProcAddress(h, name);
|
||||
if (f == nullptr)
|
||||
throw FormatRuntimeError("No such libjack function: %s", name);
|
||||
throw FmtRuntimeError("No such libjack function: {}", name);
|
||||
|
||||
result = reinterpret_cast<T>(f);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
|
||||
#include "Error.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
|
||||
#include <pulse/context.h>
|
||||
#include <pulse/error.h>
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
*/
|
||||
|
||||
#include "Handle.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "lib/fmt/RuntimeError.hxx"
|
||||
#include "util/ScopeExit.hxx"
|
||||
#include "util/StringStrip.hxx"
|
||||
|
||||
@@ -60,8 +60,8 @@ Handle::ThrowError()
|
||||
yajl_free_error(handle, str);
|
||||
};
|
||||
|
||||
throw FormatRuntimeError("Failed to parse JSON: %s",
|
||||
StripErrorMessage((char *)str));
|
||||
throw FmtRuntimeError("Failed to parse JSON: {}",
|
||||
StripErrorMessage((char *)str));
|
||||
}
|
||||
|
||||
} // namespace Yajl
|
||||
|
||||
Reference in New Issue
Block a user