errors

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2019 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package errors implements functions to manipulate compression errors.

In idiomatic Go, it is an anti-pattern to use panics as a form of error reporting in the API. Instead, the expected way to transmit errors is by returning an error value. Unfortunately, the checking of "err != nil" in tight loops commonly found in compression causes non-negligible performance degradation. While this may not be idiomatic, the internal packages of this repository rely on panics as a normal means to convey errors. In order to ensure that these panics do not leak across the public API, the public packages must recover from these panics and present an error value.

The Panic and Recover functions in this package provide a safe way to recover from errors only generated from within this repository.

Example usage:

func Foo() (err error) {
	defer errors.Recover(&err)

	if rand.Intn(2) == 0 {
		// Unexpected panics will not be caught by Recover.
		io.Closer(nil).Close()
	} else {
		// Errors thrown by Panic will be caught by Recover.
		errors.Panic(errors.New("whoopsie"))
	}
}

Index

Constants

View Source
const (
	// Unknown indicates that there is no classification for this error.
	Unknown = iota

	// Internal indicates that this error is due to an internal bug.
	// Users should file a issue report if this type of error is encountered.
	Internal

	// Invalid indicates that this error is due to the user misusing the API
	// and is indicative of a bug on the user's part.
	Invalid

	// Deprecated indicates the use of a deprecated and unsupported feature.
	Deprecated

	// Corrupted indicates that the input stream is corrupted.
	Corrupted

	// Closed indicates that the handlers are closed.
	Closed
)

Variables

This section is empty.

Functions

func IsClosed

func IsClosed(err error) bool

func IsCorrupted

func IsCorrupted(err error) bool

func IsDeprecated

func IsDeprecated(err error) bool

func IsInternal

func IsInternal(err error) bool

func IsInvalid

func IsInvalid(err error) bool

func Panic

func Panic(err error)

func Recover

func Recover(err *error)

Types

type Error

type Error struct {
	Code int    // The error type
	Pkg  string // Name of the package where the error originated
	Msg  string // Descriptive message about the error (optional)
}

func (Error) CompressError

func (e Error) CompressError()

func (Error) Error

func (e Error) Error() string

func (Error) IsClosed

func (e Error) IsClosed() bool

func (Error) IsCorrupted

func (e Error) IsCorrupted() bool

func (Error) IsDeprecated

func (e Error) IsDeprecated() bool

func (Error) IsInternal

func (e Error) IsInternal() bool

func (Error) IsInvalid

func (e Error) IsInvalid() bool

Jump to

Keyboard shortcuts

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