Skip to content

Commit

Permalink
Add EvalErrorBuilder::panic()
Browse files Browse the repository at this point in the history
An nicer alternative to printError + abort, or assert(false /* foo */)
  • Loading branch information
roberth committed Jul 11, 2024
1 parent 1352222 commit 6157740
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/libexpr/eval-error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ void EvalErrorBuilder<T>::debugThrow()
throw error;
}

template<class T>
void EvalErrorBuilder<T>::panic()
{
logError(error.info());
printError("This is a bug! An unexpected condition occurred, causing the Nix evaluator to have to stop. If you could share a reproducible example or a core dump, please open an issue at https://github.com/NixOS/nix/issues");
abort();
}

template class EvalErrorBuilder<EvalBaseError>;
template class EvalErrorBuilder<EvalError>;
template class EvalErrorBuilder<AssertionError>;
Expand Down
6 changes: 6 additions & 0 deletions src/libexpr/eval-error.hh
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ public:
* Delete the `EvalErrorBuilder` and throw the underlying exception.
*/
[[gnu::noinline, gnu::noreturn]] void debugThrow();

/**
* A programming error or fatal condition occurred. Abort the process for core dump and debugging.
* This does not print a proper backtrace, because unwinding the stack is destructive.
*/
[[gnu::noinline, gnu::noreturn]] void panic();
};

}

0 comments on commit 6157740

Please sign in to comment.