apperr

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package apperr defines the typed error contract shared by the acquisition, CLI, and MCP layers. Agents branch on codes, not on prose strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code string

Code is a stable machine-readable error code.

const (
	CodeInvalidID       Code = "invalid_id"
	CodeBadRequest      Code = "bad_request"
	CodeNotFound        Code = "not_found"
	CodeChannelNotFound Code = "channel_not_found"
	CodeNotAChannel     Code = "not_a_channel"
	CodePrivate         Code = "private"
	CodeAgeRestricted   Code = "age_restricted"
	CodeBotCheck        Code = "bot_check"
	CodeNoCaptions      Code = "no_captions"
	CodeNoMatchingLang  Code = "no_matching_language"
	CodeRateLimited     Code = "rate_limited"
	CodeBlocked         Code = "blocked"
	CodeNetwork         Code = "network"
	CodeUpstreamChanged Code = "upstream_changed"
	CodeTimeout         Code = "timeout"
	CodeInternal        Code = "internal"
)

type Error

type Error struct {
	Code               Code     `json:"code"`
	Message            string   `json:"message"`
	Retryable          bool     `json:"retryable"`
	RetryAfterSeconds  int      `json:"retry_after_seconds,omitempty"`
	AvailableLanguages []string `json:"available_languages,omitempty"`
	Suggestion         string   `json:"suggestion,omitempty"`
}

Error is both a Go error and the machine-readable payload returned to agents in structuredContent when IsError is set.

func Aggregate

func Aggregate(errs []error) *Error

Aggregate collapses the failure of the ANDROID -> IOS -> watch-page cascade into one typed error an agent can act on, preserving the most specific verdict and any Retry-After hint.

When every attempt failed with the same code the winner is not a synthetic "all methods failed" error: the most specific constituent error (longest message, then a suggestion) is preserved with its suggestion, Retry-After, and available-language list. Mixed-code failures still collapse to upstream_changed, but keep the union of actionable hints.

func As

func As(err error) (*Error, bool)

As extracts the typed error from err, if any.

func ClassifyContext

func ClassifyContext(err error) *Error

ClassifyContext turns deadline/cancellation errors into the public contract.

func ClassifyHTTPStatus

func ClassifyHTTPStatus(status int, retryAfter string) *Error

ClassifyHTTPStatus maps an upstream HTTP status to the public error contract.

func ClassifyPlayability

func ClassifyPlayability(status, reason string) *Error

ClassifyPlayability maps YouTube's playabilityStatus to the error contract.

func New

func New(code Code, format string, args ...any) *Error

New builds a typed error with a formatted message.

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL