[PATCH] D69057: [Error] Make llvm::cantFail include the original error messages
Don Hinton via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 16 10:18:52 PDT 2019
hintonda created this revision.
hintonda added reviewers: lhames, beanz.
Herald added a project: LLVM.
The current implementation eats the current errors and just outputs
the message parameter passed to llvm::cantFail. This change appends
the original error message(s), so the user can see exactly why
cantFail failed.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D69057
Files:
llvm/include/llvm/Support/Error.h
llvm/unittests/Support/ErrorTest.cpp
Index: llvm/unittests/Support/ErrorTest.cpp
===================================================================
--- llvm/unittests/Support/ErrorTest.cpp
+++ llvm/unittests/Support/ErrorTest.cpp
@@ -390,7 +390,8 @@
};
EXPECT_DEATH(FailToHandle(),
- "Failure value returned from cantFail wrapped call")
+ "Failure value returned from cantFail wrapped call\n"
+ "CustomError {7}")
<< "Unhandled Error in handleAllErrors call did not cause an "
"abort()";
}
@@ -409,7 +410,8 @@
};
EXPECT_DEATH(ReturnErrorFromHandler(),
- "Failure value returned from cantFail wrapped call")
+ "Failure value returned from cantFail wrapped call\n"
+ "CustomError {7}")
<< " Error returned from handler in handleAllErrors call did not "
"cause abort()";
}
@@ -510,11 +512,12 @@
// Test that cantFail results in a crash if you pass it a failure value.
#if LLVM_ENABLE_ABI_BREAKING_CHECKS && !defined(NDEBUG)
TEST(Error, CantFailDeath) {
- EXPECT_DEATH(
- cantFail(make_error<StringError>("foo", inconvertibleErrorCode()),
- "Cantfail call failed"),
- "Cantfail call failed")
- << "cantFail(Error) did not cause an abort for failure value";
+ EXPECT_DEATH(cantFail(make_error<StringError>("Original error message",
+ inconvertibleErrorCode()),
+ "Cantfail call failed"),
+ "Cantfail call failed\n"
+ "Original error message")
+ << "cantFail(Error) did not cause an abort for failure value";
EXPECT_DEATH(
{
Index: llvm/include/llvm/Support/Error.h
===================================================================
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -704,7 +704,10 @@
if (Err) {
if (!Msg)
Msg = "Failure value returned from cantFail wrapped call";
- llvm_unreachable(Msg);
+ std::string Str;
+ raw_string_ostream OS(Str);
+ OS << Msg << "\n" << Err;
+ llvm_unreachable(OS.str().c_str());
}
}
@@ -728,7 +731,11 @@
else {
if (!Msg)
Msg = "Failure value returned from cantFail wrapped call";
- llvm_unreachable(Msg);
+ std::string Str;
+ raw_string_ostream OS(Str);
+ auto E = ValOrErr.takeError();
+ OS << Msg << "\n" << E;
+ llvm_unreachable(OS.str().c_str());
}
}
@@ -752,7 +759,11 @@
else {
if (!Msg)
Msg = "Failure value returned from cantFail wrapped call";
- llvm_unreachable(Msg);
+ std::string Str;
+ raw_string_ostream OS(Str);
+ auto E = ValOrErr.takeError();
+ OS << Msg << "\n" << E;
+ llvm_unreachable(OS.str().c_str());
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69057.225255.patch
Type: text/x-patch
Size: 2754 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191016/9a4834d1/attachment.bin>
More information about the llvm-commits
mailing list