Skip to content

Errors

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

Variable Name Error Message Description (inferred)
moqt.ErrInvalidScheme “moqt: invalid scheme” Invalid URL scheme (only https and moqt are supported)
moqt.ErrClosedSession “moqt: closed session” Session has been closed
moqt.ErrServerClosed “moqt: server closed” Server has been closed

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 Type Description Returned By
*moqt.SessionError Error related to session management and protocol moqt.Session, or instance originating from it
*moqt.SubscribeError Error during subscribe negotiation or operation moqt.TrackWriter, moqt.TrackReader
*moqt.AnnounceError Error during announcement phase (e.g., broadcast path issues) moqt.AnnouncementWriter, moqt.AnnouncementReader
*moqt.GroupError Error in group operations (e.g., out of range, expired group) moqt.GroupWriter, moqt.GroupReader
*moqt.FetchError Error during fetch operations Session.Fetch
*moqt.ProbeError Error during probe operations Session.Probe

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

  • moqt.SessionError wraps *transport.ApplicationError and represents errors that affect the whole QUIC connection (session-level errors).
  • moqt.AnnounceError, moqt.SubscribeError, moqt.GroupError, moqt.FetchError, and moqt.ProbeError each wrap *transport.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 as a pointer, which is how the library returns it: match it with errors.As and a target such as var subErr *moqt.SubscribeError. A target of the value type is reported by go vet, and makes errors.As panic.

moq-lite-06 defines two independent code spaces: one for closing the session and one for resetting a stream. The same number means different things in each. Both reserve 0x20–0x2F (never sent, never interpreted), reuse moq-transport’s codes below 0x20, and leave 0x40 and up to the application. moq-lite’s own stream codes sit at 0x30–0x39.

Every stream code type below (AnnounceErrorCode, SubscribeErrorCode, GroupErrorCode, FetchErrorCode, ProbeErrorCode) is a view of the one stream space, so two types share a value where they share a meaning. Where gomoqt needs a code moq-lite does not define, it is assigned from 0x40 up; a peer that is not gomoqt treats it as an unspecified error.

Note that a stream reset with 0x0 is INTERNAL_ERROR, not a routine cancellation: CANCELLED is 0x1.

Code Name Value Description
moqt.NoError 0x0 Normal termination
moqt.InternalSessionErrorCode 0x1 Internal error
moqt.UnauthorizedSessionErrorCode 0x2 Authentication/authorization
moqt.ProtocolViolationErrorCode 0x3 Protocol violation
moqt.KeyValueFormattingErrorCode 0x6 A malformed or repeated key-value pair
moqt.GoAwayTimeoutErrorCode 0x10 GoAway timeout
moqt.ControlMessageTimeoutErrorCode 0x11 The peer took too long to answer a control message
moqt.VersionNegotiationFailedErrorCode 0x15 No version could be negotiated
moqt.NotSupportedErrorCode 0x40 Tokens are not verified on an Auth Stream (gomoqt)

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
}

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
}
}