|
| 1 | +#include <algorithm> |
| 2 | + |
1 | 3 | #include "mamba/core/error_handling.hpp" |
2 | 4 | #include "mamba/core/logging.hpp" |
3 | 5 |
|
@@ -55,36 +57,57 @@ namespace mamba |
55 | 57 | return m_data; |
56 | 58 | } |
57 | 59 |
|
58 | | - constexpr const char* mamba_aggregated_error::m_base_message; // = "Many errors occurred:\n"; |
| 60 | + namespace |
| 61 | + { |
| 62 | + constexpr auto* message_aggregated_error_top = "Multiple errors occurred:\n"; |
| 63 | + constexpr auto* message_aggregated_bug_report = "If you run into this error repeatedly, your package cache may be corrupted.\n" |
| 64 | + "Please try running `mamba clean -a` to remove this cache before retrying the operation.\n" |
| 65 | + "\n" |
| 66 | + "If you still are having issues, please report the error on `mamba-org/mamba`'s issue tracker:\n" |
| 67 | + "https://github.com/mamba-org/mamba/issues/new?assignees=&labels=&projects=&template=bug.yml"; |
| 68 | + |
| 69 | + } |
59 | 70 |
|
60 | | - mamba_aggregated_error::mamba_aggregated_error(error_list_t&& error_list) |
61 | | - : base_type(mamba_aggregated_error::m_base_message, mamba_error_code::aggregated) |
| 71 | + mamba_aggregated_error::mamba_aggregated_error(error_list_t&& error_list, bool with_bug_report_info) |
| 72 | + : base_type(message_aggregated_error_top, mamba_error_code::aggregated) |
62 | 73 | , m_error_list(std::move(error_list)) |
63 | 74 | , m_aggregated_message() |
| 75 | + , m_with_bug_report_message(with_bug_report_info) |
64 | 76 | { |
65 | 77 | } |
66 | 78 |
|
67 | 79 | const char* mamba_aggregated_error::what() const noexcept |
68 | 80 | { |
69 | 81 | if (m_aggregated_message.empty()) |
70 | 82 | { |
71 | | - m_aggregated_message = m_base_message; |
| 83 | + // If we have only one error, don't say it's multiple errors. |
| 84 | + if (m_error_list.size() > 1) |
| 85 | + { |
| 86 | + m_aggregated_message = message_aggregated_error_top; |
| 87 | + } |
72 | 88 |
|
73 | 89 | for (const mamba_error& er : m_error_list) |
74 | 90 | { |
75 | 91 | m_aggregated_message += er.what(); |
76 | 92 | m_aggregated_message += "\n"; |
77 | 93 | } |
78 | 94 |
|
79 | | - m_aggregated_message += "If you run into this error repeatedly, your package cache may be corrupted.\n" |
80 | | - "Please try running `mamba clean -a` to remove this cache before retrying the operation.\n" |
81 | | - "\n" |
82 | | - "If you still are having issues, please report the error on `mamba-org/mamba`'s issue tracker:\n" |
83 | | - "https://github.com/mamba-org/mamba/issues/new?assignees=&labels=&projects=&template=bug.yml"; |
| 95 | + if (m_with_bug_report_message) |
| 96 | + { |
| 97 | + m_aggregated_message += message_aggregated_bug_report; |
| 98 | + } |
84 | 99 | } |
85 | 100 | return m_aggregated_message.c_str(); |
86 | 101 | } |
87 | 102 |
|
| 103 | + bool mamba_aggregated_error::has_only_error(const mamba_error_code code) const |
| 104 | + { |
| 105 | + return std::ranges::all_of( |
| 106 | + m_error_list, |
| 107 | + [&](const auto& err) { return err.error_code() == code; } |
| 108 | + ); |
| 109 | + } |
| 110 | + |
88 | 111 | tl::unexpected<mamba_error> make_unexpected(const char* msg, mamba_error_code ec) |
89 | 112 | { |
90 | 113 | return tl::make_unexpected(mamba_error(msg, ec)); |
|
0 commit comments