1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-16 07:22:43 +01:00

libmain: Catch logger exceptions in handleExceptions

Avoid std::terminate in case logging code also
throws.

(cherry picked from commit 90d1ff4805)
This commit is contained in:
Sergei Zimmerman 2025-05-22 23:08:59 +00:00 committed by Mergify
parent b96f21441d
commit 9656003292

View file

@ -336,6 +336,7 @@ int handleExceptions(const std::string & programName, std::function<void()> fun)
ErrorInfo::programName = baseNameOf(programName); ErrorInfo::programName = baseNameOf(programName);
std::string error = ANSI_RED "error:" ANSI_NORMAL " "; std::string error = ANSI_RED "error:" ANSI_NORMAL " ";
try {
try { try {
try { try {
fun(); fun();
@ -363,6 +364,10 @@ int handleExceptions(const std::string & programName, std::function<void()> fun)
printError(error + e.what()); printError(error + e.what());
return 1; return 1;
} }
} catch (...) {
/* In case logger also throws just give up. */
return 1;
}
return 0; return 0;
} }