errors

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: BSD-3-Clause Imports: 2 Imported by: 0

README

Go Report Card coverage-badge GoDoc

Algobra: Errors

This package implements the error handling used in Algobra. Some users may find the Is function useful to test which kind of error occurred. Apart from this, the package is mainly intended for internal use.

Third party licenses

Parts of the error package are heavily inspired by the corresponding package in Upspin, which is published under the following license:

Copyright (c) 2016 The Upspin Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

   * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
   * Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
   * Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Documentation

Overview

Package errors implements error handling in algobra.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Is

func Is(kind Kind, err error) bool

Is determines if an error has a certain kind.

If err is not the Error type defined in this package, the function returns false.

Types

type Error

type Error struct {
	Op   Op    // The operation causing the error
	Kind Kind  // The kind of error
	Err  error // The underlying error
}

Error is the basic error object.

func New

func New(op Op, kind Kind, message string, formatArgs ...interface{}) *Error

New creates a new error.

The message can contain formatting directives for the inputs in formatArgs.

func Wrap

func Wrap(op Op, kind Kind, err error) *Error

Wrap takes an existing error and wraps it in a new operation and kind.

func (*Error) Error

func (e *Error) Error() string

Error formats the error as a string.

type Kind

type Kind uint8

Kind describes the kind of an error

const (
	Inherit            Kind = iota // Inherit kind when wrapping
	Input                          // General input error
	InputValue                     // Input has wrong "value" (e.g. not a monomial)
	InputIncompatible              // Inputs incompatible with each other
	InputTooLarge                  // Input exceeds some upper bound
	ArithmeticIncompat             // Objects not compatible for given operation
	Parsing                        // General parsing error
	Conversion                     // Conversion error
	Overflow                       // Overflow error
	Internal                       // Internal error
)

Defined error kinds.

type Op

type Op string

Op denotes an operation type.

Indicates the operation performed when the error occurred.

Jump to

Keyboard shortcuts

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