forked from OSchip/llvm-project
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.
This commit is contained in:
parent
0c502507f4
commit
f03689ace5
|
@ -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)); }
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue