Help us shape the future of Go! Take the 2026 Go Developer Survey

warnings

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2016 License: BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package warnings implements error handling with non-fatal errors (warnings).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FatalOnly

func FatalOnly(err error) error

FatalOnly returns the fatal error, if any, **in an error returned by a Collector**. It returns nil if and only if err is nil or err is a List with err.Fatal == nil.

func WarningsOnly

func WarningsOnly(err error) []error

WarningsOnly returns the warnings **in an error returned by a Collector**.

Types

type Collector

type Collector struct {
	// IsFatal distinguishes between warnings and fatal errors.
	IsFatal func(error) bool
	// FatalWithWarnings set to true means that a fatal error is returned as
	// a List together with all warnings so far. The default behavior is to
	// only return the fatal error and discard any warnings that have been
	// collected.
	FatalWithWarnings bool
	// contains filtered or unexported fields
}

A Collector collects errors up to the first fatal error.

func NewCollector

func NewCollector(isFatal func(error) bool) *Collector

NewCollector returs a new Collector; it uses isFatal to distinguish between warnings and fatal errors.

func (*Collector) Collect

func (c *Collector) Collect(err error) error

Collect collects a single error (warning or fatal). It return nil if collection can continue (only warnings so far), or otherwise the errors collected so far. Collect mustn't be called after the first fatal error or after Done has been called.

func (*Collector) Done

func (c *Collector) Done() error

Done ends collection and returns the collected error(s).

type List

type List struct {
	Warnings []error
	Fatal    error
}

List holds a collection of warnings and optionally one fatal error.

func (List) Error

func (l List) Error() string

Error implements the error interface.

Jump to

Keyboard shortcuts

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