ayderr

package
v0.16.7 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package ayderr is the set of error types in Ayd.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AydError

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

AydError is the error type of Ayd.

Please use errors.Is or errors.Unwrap if you want to know what kind of error is it.

func New

func New(kind error, from error, format string, args ...interface{}) AydError

New creates a new AydError.

func (AydError) Error

func (e AydError) Error() string

Error implements error interface.

func (AydError) Is

func (e AydError) Is(err error) bool

Is implement for errors.Is.

func (AydError) Unwrap

func (e AydError) Unwrap() error

Unwrap implement for errors.Unwrap.

type List

type List struct {
	// What is the error that describes what kind of errors is this.
	What error

	// Children is the detail errors in this error list.
	Children []error
}

List is a list of errors.

func (List) Error

func (l List) Error() string

Error implements error interface.

func (List) Is

func (l List) Is(err error) bool

func (List) Unwrap

func (l List) Unwrap() error

Unwrap implement for errors.Unwrap. This function returns What member.

type ListBuilder

type ListBuilder struct {
	What     error
	Children []error
}

ListBuilder is the List builder.

Example
package main

import (
	"errors"
	"fmt"

	"github.com/macrat/ayd/internal/ayderr"
)

func main() {
	// make a base error.
	ErrSomething := errors.New("something wrong")

	// prepare builder with base error.
	e := &ayderr.ListBuilder{What: ErrSomething}

	// e.Build() returns nil because builder has no child error yet.
	fmt.Println("--- before push errors ---")
	fmt.Println(e.Build())
	fmt.Println()

	// push errors as children.
	e.Push(errors.New("A is wrong"), errors.New("B is wrong"))

	// or generate error and push as a child.
	e.Pushf("%s is also wrong", "C")

	// e.Build() returns List now, because it has children.
	fmt.Println("--- after push errors ---")
	fmt.Println(e.Build())

}
Output:

--- before push errors ---
<nil>

--- after push errors ---
something wrong:
  A is wrong
  B is wrong
  C is also wrong

func (*ListBuilder) Build

func (lb *ListBuilder) Build() error

Build creates List if it has any child. It returns nil if there is no child.

func (*ListBuilder) Push

func (lb *ListBuilder) Push(err ...error)

Push appends a error as a child.

func (*ListBuilder) Pushf

func (lb *ListBuilder) Pushf(format string, values ...interface{})

Pushf calls fmt.Errorf and then push as a child of this list.

Jump to

Keyboard shortcuts

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