Errors

General Error Variables

The following error variables are defined with the prefix Err and are used for general-purpose error handling:

Variable NameError MessageDescription (inferred)
moqt.ErrInvalidScheme“moqt: invalid scheme”Invalid scheme error
moqt.ErrClosedSession“moqt: closed session”Session has been closed
moqt.ErrServerClosed“moqt: server closed”Server has been closed
moqt.ErrClientClosed“moqt: client closed”Client has been closed

Protocol Error Types

The following error types are defined to represent specific protocol error scenarios. Each type wraps error codes and provides methods for error handling and inspection:

Error TypeDescriptionReturned By
moqt.SessionErrorError related to session management and protocolmoqt.Session, or instance originating from it
moqt.SubscribeErrorError during subscribe negotiation or operationmoqt.TrackWriter, moqt.TrackReader
moqt.AnnounceErrorError during announcement phase (e.g., broadcast path issues)moqt.AnnouncementsWriter, moqt.AnnouncementsReader
moqt.GroupErrorError in group operations (e.g., out of range, expired group)moqt.GroupWriter, moqt.GroupReader

Relationship with QUIC errors

The concrete MOQ error types map directly onto the QUIC error primitives:

  • moqt.SessionError wraps *quic.ApplicationError and represents errors that affect the whole QUIC connection (session-level errors).
  • moqt.AnnounceError, moqt.SubscribeError, and moqt.GroupError each wrap *quic.StreamError and represent errors that occur on individual QUIC streams (stream-level errors).

This mapping allows protocol-specific error types to be propagated over QUIC using the appropriate QUIC error mechanism.

Each error type implements the error interface and works with Go’s standard error utilities (errors.Is, errors.As).

Built-in Error Codes

Error codes for each custom error type are summarized below. Click each section to toggle visibility.

Code NameValueDescription
moqt.NoError0x0Normal termination
moqt.InternalSessionErrorCode0x1Internal error
moqt.UnauthorizedSessionErrorCode0x2Authentication/authorization
moqt.ProtocolViolationErrorCode0x3Protocol violation
moqt.ParameterLengthMismatchErrorCode0x5Parameter length mismatch
moqt.TooManySubscribeErrorCode0x6Too many subscriptions
moqt.GoAwayTimeoutErrorCode0x10GoAway timeout
moqt.UnsupportedVersionErrorCode0x12Unsupported version
moqt.SetupFailedErrorCode0x13Setup failed
Code NameValueDescription
moqt.InternalAnnounceErrorCode0x0Internal error
moqt.DuplicatedAnnounceErrorCode0x1Duplicated broadcast path
moqt.InvalidAnnounceStatusErrorCode0x2Invalid announce status
moqt.UninterestedErrorCode0x3Uninterested
moqt.BannedPrefixErrorCode0x4Banned prefix
moqt.InvalidPrefixErrorCode0x5Invalid prefix
Code NameValueDescription
moqt.InternalSubscribeErrorCode0x00Internal error
moqt.InvalidRangeErrorCode0x01Invalid range
moqt.DuplicateSubscribeIDErrorCode0x02Duplicate subscribe ID
moqt.TrackNotFoundErrorCode0x03Track not found
moqt.UnauthorizedSubscribeErrorCode0x04Unauthorized
moqt.SubscribeTimeoutErrorCode0x05Subscribe timeout
Code NameValueDescription
moqt.InternalGroupErrorCode0x00Internal error
moqt.OutOfRangeErrorCode0x02Out of range
moqt.ExpiredGroupErrorCode0x03Expired group
moqt.SubscribeCanceledErrorCode0x04Subscribe canceled
moqt.PublishAbortedErrorCode0x05Publish aborted
moqt.ClosedSessionGroupErrorCode0x06Closed session
moqt.InvalidSubscribeIDErrorCode0x07Invalid subscribe ID

Error Handling

Implementations in gomoqt/moqt return specific error types for different error scenarios. You can use type assertions to handle these errors accordingly.

  • Example: When moqt.TrackWriter returns an error
    var subErr *moqt.SubscribeError
    if errors.As(err, &subErr) {
        // Handle SubscribeError
    }

Note:

MOQ-related errors are always returned from specific structs. When analyzing errors, make sure to perform error handling and analysis at the correct location in the code, according to the struct that returns the error. This ensures accurate diagnosis and handling of protocol errors.

Error Propagation

You can get context.Context via Context method implementated in gomoqt/moqt such as moqt.TrackReader or moqt.Session. moqt.Cause function is provided to access to the root cause of an error propagation and to parse the cause as a MOQ error if it is a QUIC error. This is because the context.Context holds the original QUIC error and context.Cause returns the cause as is.

func Cause(ctx context.Context) error

Example: Get MOQ cause from context.Context

    var ctx context.Context

    var cause error
    cause = moqt.Cause(ctx)

To get the MOQ cause from a context, use errors.As function with corresponding error type.

Example: When moqt.TrackWriter’s context is canceled

    var tw *moqt.TrackWriter
    ctx := tw.Context()

    if err := moqt.Cause(ctx); err != nil {
        var subErr *moqt.SubscribeError
        if errors.As(err, &subErr) {
            // Handle SubscribeError
        }

        var sessErr *moqt.SessionError
        if errors.As(err, &sessErr) {
            // Handle SessionError
        }
    }

Note: context.Cause

When using context.Cause, the raw QUIC error can be accessed directly from the context.