Skip to content

Commit a09e7af

Browse files
committed
chore: ExecutorGroup returns errors
1 parent 65b5279 commit a09e7af

File tree

7 files changed

+76
-394
lines changed

7 files changed

+76
-394
lines changed

docs/modules/ROOT/pages/design-notes.adoc

+9
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,12 @@ We probably don't want to store any javadocs for namespaces either.
3939
The AST visitor and metadata all use forward slashes to represent file
4040
pathnames, even on Windows. This is so the generated reference documentation
4141
does not vary based on the platform.
42+
43+
== Exceptions
44+
45+
In functions which cannot return an error, such as work submitted to a thread
46+
pool or in a constructor, the implementation usually throws `Error`. These
47+
are caught and reported, and the process exits gracefully. If any exception
48+
is thrown which is not derived from `Error`, then it should not be caught.
49+
The uncaught exception handler should print a stack trace and exit the process
50+
immediately.

include/mrdox/Support/Error.hpp

+18
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ class [[nodiscard]] MRDOX_DECL
121121
return text_;
122122
}
123123

124+
/** Return true if this equals other.
125+
*/
126+
bool
127+
operator==(Error const& other) const noexcept
128+
{
129+
return text_ == other.text_;
130+
}
131+
124132
/** Return a null-terminated error string.
125133
*/
126134
char const*
@@ -147,6 +155,16 @@ success() noexcept
147155
} // mrdox
148156
} // clang
149157

158+
template<>
159+
struct std::hash<::clang::mrdox::Error>
160+
{
161+
std::size_t operator()(
162+
::clang::mrdox::Error const& err) const noexcept
163+
{
164+
return std::hash<std::string_view>()(err.message());
165+
}
166+
};
167+
150168
//------------------------------------------------
151169

152170
template<>

include/mrdox/Support/ExecutorGroup.hpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <mrdox/Platform.hpp>
1515
#include <mrdox/Support/any_callable.hpp>
16+
#include <mrdox/Support/Error.hpp>
1617
#include <mrdox/Support/ThreadPool.hpp>
1718
#include <deque>
1819
#include <memory>
@@ -53,11 +54,17 @@ class MRDOX_DECL
5354
ExecutorGroupBase(ExecutorGroupBase&&) noexcept;
5455

5556
/** Block until all work has completed.
57+
58+
@return Zero or more errors which were
59+
thrown from submitted work.
5660
*/
57-
void
61+
[[nodiscard]]
62+
std::vector<Error>
5863
wait() noexcept;
5964
};
6065

66+
//------------------------------------------------
67+
6168
/** A set of execution agents for performing concurrent work.
6269
*/
6370
template<class Agent>

include/mrdox/Support/Report.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ reportError(
8080
err.message()));
8181
}
8282

83+
template<class Range>
84+
void
85+
reportErrors(Range const& errors)
86+
{
87+
for(auto const& err : errors)
88+
reportError(err.message());
89+
}
90+
8391
/** Report a warning to the console.
8492
8593
@param text The message contents. A newline

0 commit comments

Comments
 (0)