[llvm] f03689a - FileError: Provide a way to retrieve the underlying error string without the file name
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 8 16:17:44 PDT 2021
Author: David Blaikie
Date: 2021-09-08T16:16:54-07:00
New Revision: f03689ace598b2c5f8263bbc5afbc4e5bc33ac43
URL: https://github.com/llvm/llvm-project/commit/f03689ace598b2c5f8263bbc5afbc4e5bc33ac43
DIFF: https://github.com/llvm/llvm-project/commit/f03689ace598b2c5f8263bbc5afbc4e5bc33ac43.diff
LOG: FileError: Provide a way to retrieve the underlying error string without the file name
For use with APIs that want to report the file name in a different
syntactic form, have other knowledge of the filename, etc.
Added:
Modified:
llvm/include/llvm/Support/Error.h
llvm/unittests/Support/ErrorTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h
index 77ff2f47d463..e84033d530e0 100644
--- a/llvm/include/llvm/Support/Error.h
+++ b/llvm/include/llvm/Support/Error.h
@@ -1266,6 +1266,13 @@ class FileError final : public ErrorInfo<FileError> {
Err->log(OS);
}
+ std::string messageWithoutFileInfo() const {
+ std::string Msg;
+ raw_string_ostream OS(Msg);
+ Err->log(OS);
+ return OS.str();
+ }
+
StringRef getFileName() { return FileName; }
Error takeError() { return Error(std::move(Err)); }
diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp
index 93564026743a..d4d33027d58e 100644
--- a/llvm/unittests/Support/ErrorTest.cpp
+++ b/llvm/unittests/Support/ErrorTest.cpp
@@ -958,8 +958,13 @@ TEST(Error, FileErrorTest) {
"'file2.bin': CustomError {42}"),
0);
- Error FE5 = createFileError("", make_error<CustomError>(1));
- EXPECT_EQ(toString(std::move(FE5)).compare("'': CustomError {1}"), 0);
+ Error FE5 = createFileError("", make_error<CustomError>(5));
+ EXPECT_EQ(toString(std::move(FE5)).compare("'': CustomError {5}"), 0);
+
+ Error FE6 = createFileError("unused", make_error<CustomError>(6));
+ handleAllErrors(std::move(FE6), [](std::unique_ptr<FileError> F) {
+ EXPECT_EQ(F->messageWithoutFileInfo(), "CustomError {6}");
+ });
}
enum class test_error_code {
More information about the llvm-commits
mailing list