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 @@ public: 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(1)); - EXPECT_EQ(toString(std::move(FE5)).compare("'': CustomError {1}"), 0); + Error FE5 = createFileError("", make_error(5)); + EXPECT_EQ(toString(std::move(FE5)).compare("'': CustomError {5}"), 0); + + Error FE6 = createFileError("unused", make_error(6)); + handleAllErrors(std::move(FE6), [](std::unique_ptr F) { + EXPECT_EQ(F->messageWithoutFileInfo(), "CustomError {6}"); + }); } enum class test_error_code {