/// will be printed before the first one is logged. A newline will be printed
/// after each error.
///
+/// This function is compatible with the helpers from Support/WithColor.h. You
+/// can pass any of them as the OS. Please consider using them instead of
+/// including 'error: ' in the ErrorBanner.
+///
/// This is useful in the base level of your program to allow clean termination
/// (allowing clean deallocation of resources, etc.), while reporting error
/// information to the user.
-void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner);
+void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner = {});
/// Write all error messages (if any) in E to a string. The newline character
/// is used to separate error messages.
if (!LoadedObject) {
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(LoadedObject.takeError(), OS, "");
+ logAllUnhandledErrors(LoadedObject.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
} else {
HasError = true;
raw_string_ostream ErrStream(ErrorStr);
- logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream, "");
+ logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream);
return nullptr;
}
}
else {
HasError = true;
raw_string_ostream ErrStream(ErrorStr);
- logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream, "");
+ logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream);
return nullptr;
}
}
if (!SymTypeOrErr) {
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(SymTypeOrErr.takeError(), OS, "");
+ logAllUnhandledErrors(SymTypeOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
if (!SectionOrErr) {
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(SectionOrErr.takeError(), OS, "");
+ logAllUnhandledErrors(SectionOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
else {
HasError = true;
raw_string_ostream ErrStream(ErrorStr);
- logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream, "");
+ logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream);
return nullptr;
}
}
if (!SymTypeOrErr) {
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(SymTypeOrErr.takeError(), OS, "");
+ logAllUnhandledErrors(SymTypeOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
bool LTOModule::isThinLTO() {
Expected<BitcodeLTOInfo> Result = getBitcodeLTOInfo(MBRef);
if (!Result) {
- logAllUnhandledErrors(Result.takeError(), errs(), "");
+ logAllUnhandledErrors(Result.takeError(), errs());
return false;
}
return Result->IsThinLTO;
if (!SecOrErr) {
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(SecOrErr.takeError(), OS, "");
+ logAllUnhandledErrors(SecOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
if (!Ret) {
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(Ret.takeError(), OS, "");
+ logAllUnhandledErrors(Ret.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
if (!Ret) {
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(Ret.takeError(), OS, "");
+ logAllUnhandledErrors(Ret.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
std::string ErrMsg;
{
raw_string_ostream ErrStream(ErrMsg);
- logAllUnhandledErrors(std::move(Err), ErrStream, "");
+ logAllUnhandledErrors(std::move(Err), ErrStream);
}
report_fatal_error(ErrMsg);
}
if (!ArOrErr) {
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(ArOrErr.takeError(), OS, "");
+ logAllUnhandledErrors(ArOrErr.takeError(), OS);
OS.flush();
errs() << Buf;
exit(1);
if (!ObjErr) {
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(ObjErr.takeError(), OS, "");
+ logAllUnhandledErrors(ObjErr.takeError(), OS);
OS.flush();
errs() << "error: " << Buf;
return 1;
static void error(Error Err) {
if (!Err)
return;
- logAllUnhandledErrors(std::move(Err), WithColor::error(outs(), ""), "reading file: ");
+ logAllUnhandledErrors(std::move(Err), WithColor::error(outs()),
+ "reading file: ");
outs().flush();
exit(1);
}
if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) {
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(std::move(E), OS, "");
+ logAllUnhandledErrors(std::move(E), OS);
OS.flush();
reportError(Arc->getFileName(), Buf);
}
// This version of error() prints the archive name and member name, for example:
// "libx.a(foo.o)" after the ToolName before the error message. It sets
-// HadError but returns allowing the code to move on to other archive members.
+// HadError but returns allowing the code to move on to other archive members.
static void error(llvm::Error E, StringRef FileName, const Archive::Child &C,
StringRef ArchitectureName = StringRef()) {
HadError = true;
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(std::move(E), OS, "");
+ logAllUnhandledErrors(std::move(E), OS);
OS.flush();
errs() << " " << Buf << "\n";
}
// This version of error() prints the file name and which architecture slice it
// is from, for example: "foo.o (for architecture i386)" after the ToolName
// before the error message. It sets HadError but returns allowing the code to
-// move on to other architecture slices.
+// move on to other architecture slices.
static void error(llvm::Error E, StringRef FileName,
StringRef ArchitectureName = StringRef()) {
HadError = true;
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(std::move(E), OS, "");
+ logAllUnhandledErrors(std::move(E), OS);
OS.flush();
errs() << " " << Buf << "\n";
}
StringRef SectionName;
Obj.getSectionName(Ref, SectionName);
StringRef SegmentName = Obj.getSectionFinalSegmentName(Ref);
- if (Obj.is64Bit() &&
- Obj.getHeader64().filetype == MachO::MH_KEXT_BUNDLE &&
+ if (Obj.is64Bit() && Obj.getHeader64().filetype == MachO::MH_KEXT_BUNDLE &&
SegmentName == "__TEXT_EXEC" && SectionName == "__text")
return 't';
if (SegmentName == "__TEXT" && SectionName == "__text")
uint64_t lc_main_offset = UINT64_MAX;
for (const auto &Command : MachO->load_commands()) {
if (Command.C.cmd == MachO::LC_FUNCTION_STARTS) {
- // We found a function starts segment, parse the addresses for
+ // We found a function starts segment, parse the addresses for
// consumption.
MachO::linkedit_data_command LLC =
MachO->getLinkeditDataLoadCommand(Command);
assert(E);
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(std::move(E), OS, "");
+ logAllUnhandledErrors(std::move(E), OS);
OS.flush();
WithColor::error(errs(), ToolName) << "'" << File << "': " << Buf;
exit(1);
return *EO;
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(EO.takeError(), OS, "");
+ logAllUnhandledErrors(EO.takeError(), OS);
OS.flush();
error(Buf);
}
assert(E);
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(std::move(E), OS, "");
+ logAllUnhandledErrors(std::move(E), OS);
OS.flush();
errs() << ToolName << ": '" << File << "': " << Buf;
exit(1);
errs() << " (for architecture " << ArchitectureName << ")";
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(std::move(E), OS, "");
+ logAllUnhandledErrors(std::move(E), OS);
OS.flush();
errs() << ": " << Buf;
exit(1);
if (!Name) {
std::string Buf;
llvm::raw_string_ostream OS(Buf);
- logAllUnhandledErrors(Name.takeError(), OS, "");
+ logAllUnhandledErrors(Name.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
if (!FunctionNameOrErr) {
std::string Buf;
llvm::raw_string_ostream OS(Buf);
- logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS, "");
+ logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
if (!FunctionAddressOrErr) {
std::string Buf;
llvm::raw_string_ostream OS(Buf);
- logAllUnhandledErrors(FunctionAddressOrErr.takeError(), OS, "");
+ logAllUnhandledErrors(FunctionAddressOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
if (!Name) {
std::string Buf;
llvm::raw_string_ostream OS(Buf);
- logAllUnhandledErrors(Name.takeError(), OS, "");
+ logAllUnhandledErrors(Name.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
if (!AddressOrErr) {
std::string Buf;
llvm::raw_string_ostream OS(Buf);
- logAllUnhandledErrors(AddressOrErr.takeError(), OS, "");
+ logAllUnhandledErrors(AddressOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
if (!FunctionNameOrErr) {
std::string Buf;
llvm::raw_string_ostream OS(Buf);
- logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS, "");
+ logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
if (!FunctionAddressOrErr) {
std::string Buf;
llvm::raw_string_ostream OS(Buf);
- logAllUnhandledErrors(FunctionAddressOrErr.takeError(), OS, "");
+ logAllUnhandledErrors(FunctionAddressOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
return *EO;
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(EO.takeError(), OS, "");
+ logAllUnhandledErrors(EO.takeError(), OS);
OS.flush();
reportError(Buf);
}
if (!MaybeObj) {
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(MaybeObj.takeError(), OS, "");
+ logAllUnhandledErrors(MaybeObj.takeError(), OS);
OS.flush();
ErrorAndExit("unable to create object file: '" + Buf + "'");
}
if (!MaybeObj) {
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(MaybeObj.takeError(), OS, "");
+ logAllUnhandledErrors(MaybeObj.takeError(), OS);
OS.flush();
ErrorAndExit("unable to create object file: '" + Buf + "'");
}
if (!MaybeObj) {
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(MaybeObj.takeError(), OS, "");
+ logAllUnhandledErrors(MaybeObj.takeError(), OS);
OS.flush();
ErrorAndExit("unable to create object file: '" + Buf + "'");
}
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(std::move(E), OS, "");
+ logAllUnhandledErrors(std::move(E), OS);
OS.flush();
errs() << " " << Buf << "\n";
}
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(std::move(E), OS, "");
+ logAllUnhandledErrors(std::move(E), OS);
OS.flush();
errs() << " " << Buf << "\n";
}
Twine("Failed loading input file '") + Filename + "'",
std::make_error_code(std::errc::invalid_argument)),
TraceOrErr.takeError());
- logAllUnhandledErrors(TraceOrErr.takeError(), errs(), "");
+ logAllUnhandledErrors(TraceOrErr.takeError(), errs());
continue;
}
auto &T = *TraceOrErr;
if (!SymbolNameOrErr) {
std::string Buf;
raw_string_ostream OS(Buf);
- logAllUnhandledErrors(SymbolNameOrErr.takeError(), OS, "");
+ logAllUnhandledErrors(SymbolNameOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
Input = "<stdin>";
std::string ErrMsg;
raw_string_ostream OS(ErrMsg);
- logAllUnhandledErrors(std::move(Err), OS, "");
+ logAllUnhandledErrors(std::move(Err), OS);
OS.flush();
errs() << "Error reading file: " << Input << ": " << ErrMsg;
errs().flush();
auto Channels = createPairedQueueChannels();
- auto ReportError =
- [](Error Err) {
- logAllUnhandledErrors(std::move(Err), llvm::errs(), "");
- };
+ auto ReportError = [](Error Err) {
+ logAllUnhandledErrors(std::move(Err), llvm::errs());
+ };
// Copy the bytes out of the test object: the copy will be used to verify
// that the original is correctly transmitted over RPC to the mock layer.
auto Channels = createPairedQueueChannels();
- auto ReportError =
- [](Error Err) {
- logAllUnhandledErrors(std::move(Err), llvm::errs(), "");
- };
+ auto ReportError = [](Error Err) {
+ logAllUnhandledErrors(std::move(Err), llvm::errs());
+ };
RPCEndpoint ClientEP(*Channels.first, true);
RemoteObjectClientLayer<RPCEndpoint> Client(ClientEP, ReportError);
auto Channels = createPairedQueueChannels();
- auto ReportError =
- [](Error Err) {
- logAllUnhandledErrors(std::move(Err), llvm::errs(), "");
- };
+ auto ReportError = [](Error Err) {
+ logAllUnhandledErrors(std::move(Err), llvm::errs());
+ };
RPCEndpoint ClientEP(*Channels.first, true);
RemoteObjectClientLayer<RPCEndpoint> Client(ClientEP, ReportError);
TEST(Error, StringError) {
std::string Msg;
raw_string_ostream S(Msg);
- logAllUnhandledErrors(make_error<StringError>("foo" + Twine(42),
- inconvertibleErrorCode()),
- S, "");
+ logAllUnhandledErrors(
+ make_error<StringError>("foo" + Twine(42), inconvertibleErrorCode()), S);
EXPECT_EQ(S.str(), "foo42\n") << "Unexpected StringError log result";
auto EC =
std::string Msg;
raw_string_ostream S(Msg);
logAllUnhandledErrors(createStringError(EC, "foo%s%d0x%" PRIx8, Bar, 1, 0xff),
- S, "");
+ S);
EXPECT_EQ(S.str(), "foobar10xff\n")
<< "Unexpected createStringError() log result";
S.flush();
Msg.clear();
- logAllUnhandledErrors(createStringError(EC, Bar), S, "");
+ logAllUnhandledErrors(createStringError(EC, Bar), S);
EXPECT_EQ(S.str(), "bar\n")
<< "Unexpected createStringError() (overloaded) log result";