testerror

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package testerror contains a `Error` type that implements the standard Error interface. Other packages in this repo use this type's methods to check the error of various operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is a simple error type that allows us to chain checks using methods. However due to Go's way of handling interface types, when a nil *Error value is used as an error type (e.g. when passed into a func accepting an error) the underlying concrete type is *Error and it will not pass the usual error != nil check. Instead use the AsError() method to get a regular error type. Or use the reflect package `val := reflect.ValueOf(myCheckError); val.IsNil()`.

func New

func New(msg string) *Error

func Newf

func Newf(format string, args ...any) *Error

func (*Error) AsError

func (e *Error) AsError() error

AsError returns a regular error type that can be used in the usual way. This fixes some issues when comparing nil types, which can fail as the underlying types are different. e.g. comparing the a nil error interface type to a nil *Error type from this package can fail.

func (*Error) Error

func (e *Error) Error() string

Implement Error interface

func (*Error) ErrorContains

func (e *Error) ErrorContains(t *testing.T, substr string)

func (*Error) ErrorIsNil

func (e *Error) ErrorIsNil(t *testing.T)

func (*Error) ErrorIsNilFatal

func (e *Error) ErrorIsNilFatal(t *testing.T)

func (*Error) ErrorNotContains

func (e *Error) ErrorNotContains(t *testing.T, substr string)

func (*Error) ErrorNotNil

func (e *Error) ErrorNotNil(t *testing.T)

func (*Error) ErrorNotNilFatal

func (e *Error) ErrorNotNilFatal(t *testing.T)

Jump to

Keyboard shortcuts

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