errors

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2020 License: GPL-3.0, GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package errors is a helper package for the error type. It defines the AtariError type, an implementation of the error interface, that allows code to wrap errors around other errors and to allow normalised formatted output of error messages.

The most useful feature is deduplication of wrapped errors. This means that code does not need to worry about the immediate context of the function which creates the error. For instance:

func main() {
	err := A()
	if err != nil {
		fmt.Println(err)
	}
}

func A() error {
	err := B()
	if err != nil {
		return errors.New(errors.DebuggerError, err)
	}
	return nil
}

func B() error {
	err := C()
	if err != nil {
		return errors.New(errors.DebuggerError, rr)
	}
	return nil
}

func C() error {
	return errors.New(errors.PanicError, "C()", "not yet implemented")
}

If we follow the code from main() we can see that first error created is a PanicError, wrapped in a DebuggerError, wrapped in another DebuggerError. The message for the returned error to main() will be:

error debugging vcs: panic: C(): not yet implemented

and not

error debugging vcs: error debugging vcs: panic: C(): not yet implemented

The PanicError, used in the above example, is a special error that should be used when something has happened such that the state of the emulation (or the tool) can no longer be guaranteed.

Actual panics should only be used when the error is so terrible that there is nothing sensible to be done; useful for brute-enforcement of programming constraints and in init() functions.

Index

Constants

View Source
const (
	// panics
	PanicError = "panic: %v: %v"

	// sentinals
	UserInterrupt        = "user interrupt"
	UserQuit             = "user quit"
	ScriptEnd            = "end of script (%v)"
	PowerOff             = "emulated machine has been powered off"
	InputDeviceUnplugged = "controller unplugged from %v"
	TVOutOfSpec          = "tv out of spec: %v"

	// program modes
	PlayError        = "error emulating vcs: %v"
	DebuggerError    = "error debugging vcs: %v"
	PerformanceError = "error during performance profiling: %v"
	DisassemblyError = "error during disassembly: %v"

	// debugger
	InvalidTarget   = "invalid target (%v)"
	CommandError    = "%v"
	TerminalError   = "%v"
	GUIEventError   = "%v"
	BreakpointError = "breakpoint error: %v"

	// commandline
	ParserError     = "parser error: %v"
	HelpError       = "help error: %v"
	ValidationError = "%v"

	// dissassembly
	DisasmError    = "disasm error: %v"
	IterationError = "disasm iteration error: %v"

	// script
	ScriptFileError       = "script error: %v"
	ScriptFileUnavailable = "script error: cannot open script file (%v)"
	ScriptRunError        = "script error: use of '%v' is not allowed in scripts [%v::%d]"
	ScriptScribeError     = "script scribe error: %v"

	// recorder
	RecordingError    = "recording error: %v"
	PlaybackError     = "playback error: %v"
	PlaybackHashError = "playback error: hash error: %v"

	// database
	DatabaseError           = "database error: %v"
	DatabaseReadError       = "database error: %v [line %d]"
	DatabaseSelectEmpty     = "database error: no selected entries"
	DatabaseKeyError        = "database error: no such key in database [%v]"
	DatabaseFileUnavailable = "database error: cannot open database (%v)"

	// regression
	RegressionError         = "regression: %v"
	RegressionDigestError   = "digest regression: %v"
	RegressionPlaybackError = "playback regression: %v"

	// setup
	SetupError           = "setup error: %v"
	SetupPanelError      = "panel setup: %v"
	SetupPatchError      = "patch setup: %v"
	SetupTelevisionError = "tv setup: %v"

	// patch
	PatchError = "patch error: %v"

	// symbols
	SymbolsFileError       = "symbols error: error processing symbols file: %v"
	SymbolsFileUnavailable = "symbols error: no symbols file for %v"
	SymbolUnknown          = "symbols error: unrecognised symbol (%v)"

	// cartridgeloader
	CartridgeLoader = "cartridge loading error: %v"

	// vcs
	PolycounterError = "polycounter error: %v"

	// cpu
	InvalidResult          = "cpu error: %v"
	ProgramCounterCycled   = "cpu error: program counter cycled back to 0x0000"
	InvalidDuringExecution = "cpu error: invalid operation mid-instruction (%v)"
	CPUBug                 = "cpu bug: %v"
	// TODO: remove this once all opcodes are defined/implemented
	UnimplementedInstruction = "cpu error: unimplemented instruction (%#02x) at (%#04x)"

	// memory
	UnpokeableAddress = "memory error: cannot poke address (%v)"
	UnpeekableAddress = "memory error: cannot peek address (%v)"
	MemoryBusError    = "memory error: inaccessible address (%v)"

	// cartridges
	CartridgeError       = "cartridge error: %v"
	CartridgeEjected     = "cartridge error: no cartridge attached"
	CartridgeNotMappable = "cartridge error: bank %d can not be mapped to that address (%#04x)"
	CartridgePatchOOB    = "cartrdige error: patch offset too high (%#04x)"
	CartridgeStaticArea  = "cartridge error: static area: %v"
	SuperchargerError    = "cartridge error: AR: %v"

	// input
	UnknownInputEvent     = "input error: %v: unsupported event (%v)"
	BadInputEventType     = "input error: bad value type for event %v (expecting %s)"
	UnknownControllerType = "input error: unknown controller type (%v)"

	// television
	UnknownTVRequest = "television error: unsupported request (%v)"
	Television       = "television error: %v"

	// digests
	VideoDigest = "video digest: %v"
	AudioDigest = "audio digest: %v"

	// audio2wav
	WavWriter = "wav writer: %v"

	// gui
	UnsupportedGUIRequest = "unsupported request (%v)"
	SDLDebug              = "sdldebug: %v"
	SDLPlay               = "sdlplay: %v"
	SDLImgui              = "sdlimgui: %v"

	// hiscore server
	HiScore = "hiscore: %v"

	// linter
	Linter = "linter: %v"

	// prefs
	Prefs         = "prefs: %v"
	PrefsNoFile   = "prefs: no file (%s)"
	PrefsNotValid = "prefs: not a valid prefs file (%s)"
)

error messages

Variables

This section is empty.

Functions

func Has

func Has(err error, head string) bool

Has checks to see if the specified AtariError head appears somewhere in the sequence of wrapped errors

func Is

func Is(err error, head string) bool

Is checks if most recently wrapped error is an AtariError with a specific head

func IsAny

func IsAny(err error) bool

IsAny checks if most recently wrapped error is an AtariError, with any head

Types

type AtariError

type AtariError struct {
	Message string
	Values  Values
}

AtariError allows code to specify a predefined error and not worry too much about the message behind that error and how the message will be formatted on output.

func New

func New(message string, values ...interface{}) AtariError

New is used to create a new instance of an AtariError.

func (AtariError) Error

func (er AtariError) Error() string

Error returns the normalised error message. Most usefully, it compresses duplicate adjacent AtariError instances.

type Values

type Values []interface{}

Values is the type used to specify arguments for FormattedErrors

Jump to

Keyboard shortcuts

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