diff options
author | h0pless <[email protected]> | 2025-04-23 14:34:57 +0300 |
---|---|---|
committer | h0pless <[email protected]> | 2025-04-23 14:58:02 +0300 |
commit | f3f3e173acccdd58c3b3932acaf9319f0511531f (patch) | |
tree | 37580b1ed8702e555361784e73933059e77a8d0c | |
parent | 8cb3e5d15b053728ed62e3c10e2dc4a392aefaea (diff) |
Add new macro to replace some of the YT_VERIFYs
commit_hash:f4f2e8b9ba31109593c94251f64e1061f00af304
-rw-r--r-- | library/cpp/yt/error/public.h | 13 | ||||
-rw-r--r-- | library/cpp/yt/logging/logger.h | 18 |
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)(); \ |