mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 12:15:09 -05:00
Composing error messages for `llvm::Error` is either done by using
`llvm::createStringError()` with an appropriate format string and
arguments or by writing to a `std::string`-backed
`llvm::raw_string_ostream` and passing the result to
`llvm::make_error<llvm::StringError>()` verbatim.
The new class `StreamStringError` encapsulates the latter solution
into a class with an appropriate stream operator and implicit cast
operators to `llvm::Error` and `llvm::Expected`.
Example usage:
llvm::Error foo(int i, size_t s, ...) {
...
if(...) {
return StreamStringError()
<< "Some error message with an integer: "
<< i << " and a size_t: " << s;
}
...
}
13 lines
369 B
C++
13 lines
369 B
C++
#include <zamalang/Support/Error.h>
|
|
|
|
namespace mlir {
|
|
namespace zamalang {
|
|
// Specialized `operator<<` for `llvm::Error` that marks the error
|
|
// as checked through `std::move` and `llvm::toString`
|
|
StreamStringError &operator<<(StreamStringError &se, llvm::Error &err) {
|
|
se << llvm::toString(std::move(err));
|
|
return se;
|
|
}
|
|
} // namespace zamalang
|
|
} // namespace mlir
|