From 1f607b5def1b06003578239484c3fe250c267faf Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Fri, 29 Aug 2025 00:02:11 +0300 Subject: [PATCH] libutil: Try to call std::terminate for panic We now have a terminate handler that prints a stack trace, which is useful to have when encountering an unreachable. --- src/libutil/error.cc | 2 +- src/libutil/include/nix/util/error.hh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libutil/error.cc b/src/libutil/error.cc index b50b1f3be..c36026f6c 100644 --- a/src/libutil/error.cc +++ b/src/libutil/error.cc @@ -436,7 +436,7 @@ void panic(std::string_view msg) writeErr("\n\n" ANSI_RED "terminating due to unexpected unrecoverable internal error: " ANSI_NORMAL); writeErr(msg); writeErr("\n"); - abort(); + std::terminate(); } void panic(const char * file, int line, const char * func) diff --git a/src/libutil/include/nix/util/error.hh b/src/libutil/include/nix/util/error.hh index bd21e02d3..549116c4d 100644 --- a/src/libutil/include/nix/util/error.hh +++ b/src/libutil/include/nix/util/error.hh @@ -299,20 +299,20 @@ using NativeSysError = void throwExceptionSelfCheck(); /** - * Print a message and abort(). + * Print a message and std::terminate(). */ [[noreturn]] void panic(std::string_view msg); /** - * Print a basic error message with source position and abort(). + * Print a basic error message with source position and std::terminate(). * Use the unreachable() macro to call this. */ [[noreturn]] void panic(const char * file, int line, const char * func); /** - * Print a basic error message with source position and abort(). + * Print a basic error message with source position and std::terminate(). * * @note: This assumes that the logger is operational */