summaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorAlexander Smirnov <[email protected]>2025-04-24 00:52:06 +0000
committerAlexander Smirnov <[email protected]>2025-04-24 00:52:06 +0000
commit514f9b2af9d5384875cf0dbf50b64cdb84fffc84 (patch)
treed939c6b413c0aad4c9ca53f58b93056a60420e5d /library/cpp
parent0ab1114c86c011bbb7bda529bdf1885732d839f9 (diff)
parentcecbcb67c89297b8e37981073b0fe887418b0993 (diff)
Merge branch 'rightlib' into merge-libs-250424-0050
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/yt/error/public.h13
-rw-r--r--library/cpp/yt/logging/logger.h18
2 files changed, 25 insertions, 6 deletions
diff --git a/library/cpp/yt/error/public.h b/library/cpp/yt/error/public.h
index 77ce70ee07f..ca043976278 100644
--- a/library/cpp/yt/error/public.h
+++ b/library/cpp/yt/error/public.h
@@ -18,12 +18,13 @@ struct TOriginAttributes;
////////////////////////////////////////////////////////////////////////////////
YT_DEFINE_ERROR_ENUM(
- ((OK) (0))
- ((Generic) (1))
- ((Canceled) (2))
- ((Timeout) (3))
- ((FutureCombinerFailure) (4))
- ((FutureCombinerShortcut)(5))
+ ((Fatal) (-1))
+ ((OK) (0))
+ ((Generic) (1))
+ ((Canceled) (2))
+ ((Timeout) (3))
+ ((FutureCombinerFailure) (4))
+ ((FutureCombinerShortcut) (5))
);
////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/yt/logging/logger.h b/library/cpp/yt/logging/logger.h
index dfa1b79bac8..1b40b42053a 100644
--- a/library/cpp/yt/logging/logger.h
+++ b/library/cpp/yt/logging/logger.h
@@ -327,6 +327,24 @@ void LogStructuredEvent(
#define YT_LOG_FATAL_IF(condition, ...) if (Y_UNLIKELY(condition)) YT_LOG_FATAL(__VA_ARGS__)
#define YT_LOG_FATAL_UNLESS(condition, ...) if (!Y_LIKELY(condition)) YT_LOG_FATAL(__VA_ARGS__)
+/*
+ * A few noteworthy observations:
+ * 1. This function is meant to be used in places where YT_VERIFY won't look out of place, but
+ * it's safe to just throw an exception. Because of this, this error should not be handled by
+ * clients in any specific way.
+ * 2. Most places where this could be used have trace_id enabled, which would make it easy for
+ * administrators to find a correlation between an alert and an error, if a user were to report it.
+ * 3. Administrators will receive this alert, so there is no need to enrich the error with
+ * additional information.
+ */
+#define YT_LOG_ALERT_AND_THROW(...) \
+ YT_LOG_EVENT(Logger, ::NYT::NLogging::ELogLevel::Alert, __VA_ARGS__); \
+ THROW_ERROR_EXCEPTION( \
+ ::NYT::EErrorCode::Fatal, \
+ "Malformed request or incorrect state detected");
+#define YT_LOG_ALERT_AND_THROW_IF(condition, ...) if (condition) YT_LOG_ALERT_AND_THROW(__VA_ARGS__)
+#define YT_LOG_ALERT_AND_THROW_UNLESS(condition, ...) if (!(condition)) YT_LOG_ALERT_AND_THROW(__VA_ARGS__)
+
#define YT_LOG_EVENT(logger, level, ...) \
do { \
const auto& logger__ = (logger)(); \