forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add util::Result multiple error and warning messages
Add util::Result support for returning warning messages and multiple errors, not just a single error string. This provides a way for functions to report errors and warnings in a standard way, and simplifies interfaces. The functionality is unit tested here, and put to use in followup PR bitcoin#25722
- Loading branch information
Showing
5 changed files
with
244 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2024 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or https://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <util/result.h> | ||
|
||
#include <algorithm> | ||
#include <initializer_list> | ||
#include <iterator> | ||
#include <util/translation.h> | ||
|
||
namespace util { | ||
namespace detail { | ||
bilingual_str JoinMessages(const Messages& messages) | ||
{ | ||
bilingual_str result; | ||
for (const auto& messages : {messages.errors, messages.warnings}) { | ||
for (const auto& message : messages) { | ||
if (!result.empty()) result += Untranslated(" "); | ||
result += message; | ||
} | ||
} | ||
return result; | ||
} | ||
} // namespace detail | ||
|
||
void ResultTraits<Messages>::Update(Messages& dst, Messages& src) { | ||
dst.errors.insert(dst.errors.end(), std::make_move_iterator(src.errors.begin()), std::make_move_iterator(src.errors.end())); | ||
dst.warnings.insert(dst.warnings.end(), std::make_move_iterator(src.warnings.begin()), std::make_move_iterator(src.warnings.end())); | ||
src.errors.clear(); | ||
src.warnings.clear(); | ||
} | ||
} // namespace util |
Oops, something went wrong.