111111 XX(ERROR_STREAM_DISPOSING, 1098 , " StreamDisposing" , " Stream is disposing" ) \
112112 XX(ERROR_NOT_IMPLEMENTED, 1099 , " NotImplemented" , " Feature is not implemented" ) \
113113 XX(ERROR_NOT_SUPPORTED, 1100 , " NotSupported" , " Feature is not supported" ) \
114- XX(ERROR_SYSTEM_FILE_UNLINK, 1101 , " FileUnlink" , " Failed to unlink file" )
114+ XX(ERROR_SYSTEM_FILE_UNLINK, 1101 , " FileUnlink" , " Failed to unlink file" ) \
115+ XX(ERROR_SYSTEM_AUTH, 1102 , " SystemAuth" , " Failed to authenticate stream" )
116+
115117
116118/* *************************************************/
117119/* RTMP protocol error. */
380382 XX(ERROR_RTSP_NO_TRACK, 5039 , " RtspNoTrack" , " Drop RTSP packet for track not found" ) \
381383 XX(ERROR_RTSP_TOKEN_NOT_NORMAL, 5040 , " RtspToken" , " Invalid RTSP token state not normal" ) \
382384 XX(ERROR_RTSP_REQUEST_HEADER_EOF, 5041 , " RtspHeaderEof" , " Invalid RTSP request for header EOF" ) \
383- XX(ERROR_RTSP_NEED_MORE_DATA, 5042 , " RtspNeedMoreData" , " Need more data to complete RTCP frame parsing" )
385+ XX(ERROR_RTSP_NEED_MORE_DATA, 5042 , " RtspNeedMoreData" , " Need more data to complete RTCP frame parsing" ) \
386+ XX(ERROR_RTC_INVALID_SDP, 5043 , " RtcInvalidSdp" , " Invalid SDP for RTC" )
384387
385388/* *************************************************/
386389/* SRT protocol error. */
@@ -465,6 +468,7 @@ class SrsCplxError
465468public:
466469 static SrsCplxError *create (const char *func, const char *file, int line, int code, const char *fmt, ...);
467470 static SrsCplxError *wrap (const char *func, const char *file, int line, SrsCplxError *err, const char *fmt, ...);
471+ static SrsCplxError *transform (const char *func, const char *file, int line, int code, SrsCplxError *err, const char *fmt, ...);
468472 static SrsCplxError *success ();
469473 static SrsCplxError *copy (SrsCplxError *from);
470474 static std::string description (SrsCplxError *err);
@@ -479,13 +483,73 @@ class SrsCplxError
479483
480484// Error helpers, should use these functions to new or wrap an error.
481485#define srs_success NULL // SrsCplxError::success()
482- #define srs_error_new (ret, fmt, ...) SrsCplxError::create(__FUNCTION__, __FILE__, __LINE__, ret, fmt, ##__VA_ARGS__)
486+
487+ // Create a new error with the specified error code and message.
488+ //
489+ // Example:
490+ // if (fd < 0) {
491+ // return srs_error_new(ERROR_SOCKET_CREATE, "create socket fd=%d", fd);
492+ // }
493+ #define srs_error_new (code, fmt, ...) SrsCplxError::create(__FUNCTION__, __FILE__, __LINE__, code, fmt, ##__VA_ARGS__)
494+
495+ // Wrap an existing error with additional context. The error code is
496+ // preserved from the wrapped error.
497+ //
498+ // Example:
499+ // if ((err = do_connect(host, port)) != srs_success) {
500+ // return srs_error_wrap(err, "connect to %s:%d", host.c_str(), port);
501+ // }
483502#define srs_error_wrap (err, fmt, ...) SrsCplxError::wrap(__FUNCTION__, __FILE__, __LINE__, err, fmt, ##__VA_ARGS__)
503+
504+ // Transform an error by wrapping it and changing its error code. Useful
505+ // for converting internal errors to protocol-specific error codes (e.g.,
506+ // HTTP, RTMP). The wrapped error chain is preserved.
507+ //
508+ // Example:
509+ // if ((err = http_hooks_on_publish(ruc->req_)) != srs_success) {
510+ // return srs_error_transform(ERROR_SYSTEM_AUTH, err, "RTC: http_hooks_on_publish");
511+ // }
512+ #define srs_error_transform (code, err, fmt, ...) SrsCplxError::transform(__FUNCTION__, __FILE__, __LINE__, code, err, fmt, ##__VA_ARGS__)
513+
514+ // Copy an error object. Returns a new error object with the same content.
515+ //
516+ // Example:
517+ // srs_error_t err_copy = srs_error_copy(err);
484518#define srs_error_copy (err ) SrsCplxError::copy(err)
519+
520+ // Get the full description of an error including the entire error chain.
521+ //
522+ // Example:
523+ // srs_error_t err = do_something();
524+ // srs_warn("error: %s", srs_error_desc(err).c_str());
485525#define srs_error_desc (err ) SrsCplxError::description(err)
526+
527+ // Get a brief summary of an error (only the top-level message).
528+ //
529+ // Example:
530+ // srs_error_t err = do_something();
531+ // srs_trace("error summary: %s", srs_error_summary(err).c_str());
486532#define srs_error_summary (err ) SrsCplxError::summary(err)
533+
534+ // Get the error code as an integer.
535+ //
536+ // Example:
537+ // int code = srs_error_code(err);
538+ // if (code == ERROR_SOCKET_TIMEOUT) { ... }
487539#define srs_error_code (err ) SrsCplxError::error_code(err)
540+
541+ // Get the error code as a short string (e.g., "SocketTimeout").
542+ //
543+ // Example:
544+ // string code_str = srs_error_code_str(err);
545+ // srs_trace("error code: %s", code_str.c_str());
488546#define srs_error_code_str (err ) SrsCplxError::error_code_str(err)
547+
548+ // Get the error code description (e.g., "Socket io timeout").
549+ //
550+ // Example:
551+ // string desc = srs_error_code_strlong(err);
552+ // srs_warn("error description: %s", desc.c_str());
489553#define srs_error_code_strlong (err ) SrsCplxError::error_code_strlong(err)
490554
491555#ifndef srs_assert
0 commit comments