From 18ba2032add32b27212d1f0cb51832448fa8cfcc Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 25 Feb 2024 18:17:25 +1000 Subject: [PATCH] Error: Add AddPrefix()/AddSuffix() --- src/common/error.cpp | 24 +++++++++++++++++++++++- src/common/error.h | 5 +++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/common/error.cpp b/src/common/error.cpp index 4f48548ca..32c8e62d3 100644 --- a/src/common/error.cpp +++ b/src/common/error.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #include "error.h" @@ -232,6 +232,28 @@ Error Error::CreateHResult(long err) #endif +void Error::AddPrefix(std::string_view prefix) +{ + m_description.insert(0, prefix); +} + +void Error::AddSuffix(std::string_view suffix) +{ + m_description.append(suffix); +} + +void Error::AddPrefix(Error* errptr, std::string_view prefix) +{ + if (errptr) + errptr->AddPrefix(prefix); +} + +void Error::AddSuffix(Error* errptr, std::string_view prefix) +{ + if (errptr) + errptr->AddSuffix(prefix); +} + Error& Error::operator=(const Error& e) = default; Error& Error::operator=(Error&& e) = default; diff --git a/src/common/error.h b/src/common/error.h index 2d9190451..7a19401af 100644 --- a/src/common/error.h +++ b/src/common/error.h @@ -89,6 +89,11 @@ public: Error::SetString(errptr, fmt::vformat(fmt, fmt::make_format_args(args...))); } + void AddPrefix(std::string_view prefix); + void AddSuffix(std::string_view suffix); + static void AddPrefix(Error* errptr, std::string_view prefix); + static void AddSuffix(Error* errptr, std::string_view prefix); + Error& operator=(const Error& e); Error& operator=(Error&& e); bool operator==(const Error& e) const;