Seastar's on_internal_error() is a useful replacement for assert() but it's inconvenient that it requires each caller to supply a logger - which is often inconvenient, especially when the caller is a header file. So in this patch we introduce a utils::on_internal_error() function which is the same as seastar::on_internal_error() (the former calls the latter), except it uses a single logger instead of asking the caller to pass a logger. Refs #7871 Signed-off-by: Nadav Har'El <nyh@scylladb.com>
34 lines
1.1 KiB
C++
34 lines
1.1 KiB
C++
/*
|
|
* Copyright (C) 2024-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
// Seastar's on_internal_error() is a replacement for assert(). Instead of
|
|
// crashing like 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);
|
|
|
|
} |