utils::on_internal_error() is a wrapper for Seastar's on_internal_error()
which does not require a logger parameter - because it always uses one
logger ("on_internal_error"). Not needing a unique logger is especially
important when using on_internal_error() in a header file, where we
can't define a logger.
Seastar also has a another similar function, on_fatal_internal_error(),
for which we forgot to implement a "utils" version (without a logger
parameter). This patch fixes that oversight.
In the next patch, we need to use on_fatal_internal_error() in a header
file, so the "utils" version will be useful. We will need the fatal
version because we will encounter an unexpected situation during server
destruction, and if we let the regular on_internal_error() just throw
an exception, we'll be left in an undefined state.
Signed-off-by: Nadav Har'El <nyh@scylladb.com>
42 lines
1.4 KiB
C++
42 lines
1.4 KiB
C++
/*
|
|
* Copyright (C) 2024-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
|
|
*/
|
|
|
|
// Seastar's on_internal_error() is a replacement for SCYLLA_ASSERT(). Instead of
|
|
// crashing like SCYLLA_ASSERT(), on_internal_error() logs a message with a
|
|
// backtrace and throws an exception (and optionally also crashes - this can
|
|
// be useful for testing). However, Seastar's function is inconvenient because
|
|
// it requires specifying a logger. This makes it hard to call it from source
|
|
// files which don't already have a logger, or in code in a header file.
|
|
//
|
|
// So here we provide Scylla's version of on_internal_error() which uses a
|
|
// single logger for all internal errors - with no need to specify a logger
|
|
// object to each call.
|
|
|
|
#pragma once
|
|
|
|
#include <string_view>
|
|
|
|
namespace utils {
|
|
|
|
/// Report an internal error
|
|
///
|
|
/// Depending on the value passed to seastar::set_abort_on_internal_error(),
|
|
/// this will either abort or throw a std::runtime_error.
|
|
/// In both cases an error will be logged, containing \p reason and the
|
|
/// current backtrace.
|
|
[[noreturn]] void on_internal_error(std::string_view reason);
|
|
|
|
/// Report an internal error and abort unconditionally
|
|
///
|
|
/// The error will be logged, containing \p reason and the current backtrace,
|
|
/// and the program will be aborted, regardless of the abort_on_internal_error
|
|
/// setting.
|
|
[[noreturn]] void on_fatal_internal_error(std::string_view reason) noexcept;
|
|
|
|
}
|