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;