output

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package output holds the JSON envelope and the stable error/exit-code contract.

Index

Constants

View Source
const (
	ExitOK       = 0
	ExitInternal = 1
	ExitUsage    = 2
	ExitAuth     = 3 // not logged in, or blocked by read-only mode
	ExitNotFound = 4 // not found or ambiguous
	ExitRPC      = 5 // Telegram RPC error or flood wait
	ExitLockBusy = 6
	ExitWatcher  = 7 // watcher refused to send
)

Exit codes.

View Source
const (
	CodeUsage          = "usage"
	CodeAuth           = "auth"
	CodeReadOnly       = "readonly"
	CodeNotFound       = "not_found"
	CodeAmbiguous      = "ambiguous"
	CodeTelegram       = "telegram"
	CodeFloodWait      = "flood_wait"
	CodeLockBusy       = "lock_busy"
	CodeWatcherRefused = "watcher_refused"
	CodeInternal       = "internal"
)

Error codes (the "code" field of the error object).

View Source
const SchemaVersion = "1"

SchemaVersion is bumped on breaking changes to the JSON shapes.

Variables

This section is empty.

Functions

func Failure

func Failure(w io.Writer, err error) int

Failure writes {"schema_version":"1","ok":false,"error":{…}} and returns the exit code.

func Success

func Success(w io.Writer, data any) error

Success writes {"schema_version":"1","ok":true,"data":…}.

Types

type Error

type Error struct {
	Code    string         `json:"code"`
	Message string         `json:"message"`
	Details map[string]any `json:"details,omitempty"`
	Exit    int            `json:"-"`
}

Error is an error with a stable code and exit status.

func Ambiguous

func Ambiguous(format string, a ...any) *Error

func As

func As(err error) *Error

As returns err as *Error, wrapping unknown errors as internal.

func Auth

func Auth(format string, a ...any) *Error

func FloodWait

func FloodWait(seconds int) *Error

func Internal

func Internal(format string, a ...any) *Error

func LockBusy

func LockBusy(format string, a ...any) *Error

func NotFound

func NotFound(format string, a ...any) *Error

func ReadOnly

func ReadOnly(format string, a ...any) *Error

func Telegram

func Telegram(format string, a ...any) *Error

func Usage

func Usage(format string, a ...any) *Error

func WatcherRefused

func WatcherRefused(format string, a ...any) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) WithDetail

func (e *Error) WithDetail(k string, v any) *Error

WithDetail returns e with an extra detail field.

Jump to

Keyboard shortcuts

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