• Stars
    star
    228
  • Rank 169,511 (Top 4 %)
  • Language
    Go
  • License
    Other
  • Created over 10 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Error tracing and annotation.

errors

-- import "github.com/juju/errgo"

The errors package provides a way to create and diagnose errors. It is compatible with the usual Go error idioms but adds a way to wrap errors so that they record source location information while retaining a consistent way for code to inspect errors to find out particular problems.

Usage

func Any

func Any(error) bool

Any returns true. It can be used as an argument to Mask to allow any diagnosis to pass through to the wrapped error.

func Cause

func Cause(err error) error

Cause returns the cause of the given error. If err does not implement Causer or its Cause method returns nil, it returns err itself.

Cause is the usual way to diagnose errors that may have been wrapped by Mask or NoteMask.

func Details

func Details(err error) string

Details returns information about the stack of underlying errors wrapped by err, in the format:

[{filename:99: error one} {otherfile:55: cause of error one}]

The details are found by type-asserting the error to the Locationer, Causer and Wrapper interfaces. Details of the underlying stack are found by recursively calling Underlying when the underlying error implements Wrapper.

func Is

func Is(err error) func(error) bool

Is returns a function that returns whether the an error is equal to the given error. It is intended to be used as a "pass" argument to Mask and friends; for example:

return errors.Mask(err, errors.Is(http.ErrNoCookie))

would return an error with an http.ErrNoCookie cause only if that was err's diagnosis; otherwise the diagnosis would be itself.

func Mask

func Mask(underlying error, pass ...func(error) bool) error

Mask returns an Err that wraps the given underyling error. The error message is unchanged, but the error location records the caller of Mask.

If err is nil, Mask returns nil.

By default Mask conceals the cause of the wrapped error, but if pass(Cause(err)) returns true for any of the provided pass functions, the cause of the returned error will be Cause(err).

For example, the following code will return an error whose cause is the error from the os.Open call when (and only when) the file does not exist.

f, err := os.Open("non-existent-file")
if err != nil {
	return errors.Mask(err, os.IsNotExist)
}

In order to add context to returned errors, it is conventional to call Mask when returning any error received from elsewhere.

func MaskFunc

func MaskFunc(allow ...func(error) bool) func(error, ...func(error) bool) error

MaskFunc returns an equivalent of Mask that always allows the specified causes in addition to any causes specified when the returned function is called.

It is defined for convenience, for example when all calls to Mask in a given package wish to allow the same set of causes to be returned.

func New

func New(s string) error

New returns a new error with the given error message and no cause. It is a drop-in replacement for errors.New from the standard library.

func Newf

func Newf(f string, a ...interface{}) error

Newf returns a new error with the given printf-formatted error message and no cause.

func NoteMask

func NoteMask(underlying error, msg string, pass ...func(error) bool) error

NoteMask returns an Err that has the given underlying error, with the given message added as context, and allowing the cause of the underlying error to pass through into the result if allowed by the specific pass functions (see Mask for an explanation of the pass parameter).

func Notef

func Notef(underlying error, f string, a ...interface{}) error

Notef returns an Error that wraps the given underlying error and adds the given formatted context message. The returned error has no cause (use NoteMask or WithCausef to add a message while retaining a cause).

func WithCausef

func WithCausef(underlying, cause error, f string, a ...interface{}) error

WithCausef returns a new Error that wraps the given (possibly nil) underlying error and associates it with the given cause. The given formatted message context will also be added.

type Causer

type Causer interface {
	Cause() error
}

Causer is the type of an error that may provide an error cause for error diagnosis. Cause may return nil if there is no cause (for example because the cause has been masked).

type Err

type Err struct {
	// Message_ holds the text of the error message. It may be empty
	// if Underlying is set.
	Message_ string

	// Cause_ holds the cause of the error as returned
	// by the Cause method.
	Cause_ error

	// Underlying holds the underlying error, if any.
	Underlying_ error

	// Location holds the source code location where the error was
	// created.
	Location_ Location
}

Err holds a description of an error along with information about where the error was created.

It may be embedded in custom error types to add extra information that this errors package can understand.

func (*Err) Cause

func (e *Err) Cause() error

Cause implements Causer.

func (*Err) Error

func (e *Err) Error() string

Error implements error.Error.

func (*Err) GoString

func (e *Err) GoString() string

GoString returns the details of the receiving error message, so that printing an error with %#v will produce useful information.

func (*Err) Location

func (e *Err) Location() Location

Location implements Locationer.

func (*Err) Message

func (e *Err) Message() string

Message returns the top level error message.

func (*Err) SetLocation

func (e *Err) SetLocation(callDepth int)

Locate records the source location of the error by setting e.Location, at callDepth stack frames above the call.

func (*Err) Underlying

func (e *Err) Underlying() error

Underlying returns the underlying error if any.

type Location

type Location struct {
	File string
	Line int
}

Location describes a source code location.

func (Location) IsSet

func (loc Location) IsSet() bool

IsSet reports whether the location has been set.

func (Location) String

func (loc Location) String() string

String returns a location in filename.go:99 format.

type Locationer

type Locationer interface {
	Location() Location
}

Location can be implemented by any error type that wants to expose the source location of an error.

type Wrapper

type Wrapper interface {
	// Message returns the top level error message,
	// not including the message from the underlying
	// error.
	Message() string

	// Underlying returns the underlying error, or nil
	// if there is none.
	Underlying() error
}

Wrapper is the type of an error that wraps another error. It is exposed so that external types may implement it, but should in general not be used otherwise.

More Repositories

1

ratelimit

Efficient token-bucket-based rate limiter package.
Go
2,679
star
2

juju

Orchestration engine that enables the deployment, integration and lifecycle management of applications at any scale, on any infrastructure (Kubernetes or otherwise).
Go
2,288
star
3

errors

Common juju errors and functions to annotate errors. Based on juju/errgo
Go
1,382
star
4

utils

General utility functions
Go
212
star
5

juju-gui

Juju-GUI is a web-based GUI for Juju <https://jujucharms.com/>.
JavaScript
182
star
6

loggo

A logging library for Go. Doesn't use the built in go log standard library, but instead offers a replacement.
Go
134
star
7

fslock

Go
123
star
8

persistent-cookiejar

cookiejar is a fork of net/http/cookiejar that allows serialisation of the stored cookies
Go
111
star
9

cheatsheet

A Juju Quicksheet with some common usage examples
58
star
10

python-libjuju

Python library for the Juju API
Python
55
star
11

charm-championship

Submissions for the Juju Charm Championship
43
star
12

charm-tools

Tools for charm authors and maintainers
Python
42
star
13

httprequest

JSON-oriented HTTP server and client helpers
Go
38
star
14

cmd

A command line implementation framework
Go
27
star
15

plugins

Basic collection of the first few plugins for Juju
Python
27
star
16

gomaasapi

Go bindings for talking to MAAS
Go
26
star
17

pubsub

Publish and subscribe functionality within a single process in Go.
Go
24
star
18

mutex

Provides a named machine level mutex shareable between processes.
Go
24
star
19

gnuflag

GNU-compatible flag handling with a stdlib-like API for Go
Go
24
star
20

docs

Juju documentation, edited on https://discourse.charmhub.io/, and published on https://juju.is/docs
22
star
21

ansiterm

Colored writers and tabwriters.
Go
22
star
22

layer-index

Index of layers for building charms
Python
21
star
23

gocharm

Write your charms in Go!
Go
20
star
24

testing

Testing gocheck suites and checkers used across juju projects
Go
19
star
25

terraform-provider-juju

A Terraform provider for Juju
Go
18
star
26

charm-helpers

Python
18
star
27

retry

The retry package encapsulates the mechanism around retrying commands.
Go
18
star
28

amulet

Testing harness and tools for Juju Charms
Python
17
star
29

zaputil

Utility functions related to the zap logging package
Go
16
star
30

charmstore

The charm store server.
Go
15
star
31

charm

Parsing and testing Juju charms
Go
13
star
32

clock

Clock definition and a testing clock.
Go
11
star
33

xml

A fork of the Go xml package with fixed marshaling
Go
10
star
34

juju-academy

Learn to use Juju
JavaScript
10
star
35

mgosession

Session pooling for the mgo package
Go
10
star
36

juju-crashdump

Script to assist in gathering logs and other debugging info from a Juju model
Python
10
star
37

charmstore-client

Client for charmstore.
Go
9
star
38

worker

Utilities for handling long lived Go workers
Go
9
star
39

juju-talks

Presentations about Juju, pull requests welcome!
HTML
9
star
40

js-libjuju

JavaScript API client for Juju
TypeScript
9
star
41

firestealer

A command line tool for parsing Prometheus metrics
Python
8
star
42

zip

Fork of Go's zip package with append feature.
Go
8
star
43

httpgovernor

HTTP request concurrency limiter
Go
7
star
44

replicaset

Create and manage mongodb replicasets.
Go
7
star
45

packaging

An abstraction of different linux packaging systems.
Go
6
star
46

chaos-monkey

A tool to instrument chaos into a Juju environment.
Python
6
star
47

schema

coerce dynamically typed data structures into known forms.
Go
6
star
48

hello-juju-charm

The charm for the hello-juju application.
Python
5
star
49

theblues

Python library for the juju charmstore (v4)
Python
5
star
50

names

A package to deal with juju names (services, units, machines, etc)
Go
5
star
51

1.25-upgrade

Tools to upgrade and move a 1.25 environment to a 2.2.4+ controller
Go
4
star
52

jujusvg

Generate svgs from Juju bundles and environment.
Go
4
star
53

jenkins-github-lander

Web service to aid in landing approved branches automatically with a final test run through jenkins.
Python
4
star
54

juju-tosca

Juju Tosca Translator
Python
4
star
55

go-oracle-cloud

Go client interfacing with the oracle IAAS cloud API.
Go
4
star
56

aclstore

A simple persistent store for ACLs, with HTTP API
Go
3
star
57

txjuju

A Twisted-based Juju client
Python
3
star
58

bakeryjs

Javascript implementation of the Macaroon Bakery
TypeScript
3
star
59

qthttptest

Check that JSON HTTP endpoints respond appropriately; compatible with quicktest.
Go
3
star
60

juju-restore

Restore script for Juju controllers
Go
3
star
61

bundlechanges

A Go library to generate the list of changes required to deploy a bundle
Go
3
star
62

concurrency-limiter

Limit the number of asynchronous concurrent tasks running
JavaScript
2
star
63

postgrestest

Go support for testing against a live Postgres database
Go
2
star
64

juju-gui-charm

Charm for Juju GUI.
Python
2
star
65

mgo

The MongoDB driver for Go
Go
2
star
66

autopilot-log-collector

Python
2
star
67

hello-juju

A simple application used to demonstrate juju relations.
HTML
2
star
68

mgopurge

A tool to repair broken mgo/txn transaction references in a Juju MongoDB instance.
Go
2
star
69

httpprof

httpprof is a fork of net/http/pprof which works correctly when not at the server's root
Go
2
star
70

mgoutil

A Go package holding utilities related to the mgo package
Go
2
star
71

blobstore

This package provides a Mongo GridFS-backed blob storage engine.
Go
2
star
72

lru

A Go implementation of a least-recently-used cache
Go
2
star
73

description

Describes the Juju 2.x and 3.x serialization format of a model
Go
2
star
74

charmrepo

Charm repositories and charmstore client packages
Go
2
star
75

version

Go
2
star
76

webbrowser

Go helpers for interacting with Web browsers.
Go
2
star
77

fake-juju

A juju binary using the dummy provider for integration test purposes.
Go
2
star
78

juju-qa-jenkins

Jenkins configuration for Juju CI
Python
2
star
79

termserver

LXD image builder for the jujushell service
Makefile
1
star
80

rfc

Go implementations of various standards, particularly IETF RFCs.
Go
1
star
81

juju-bundlelib

A Python library for working with Juju bundles.
Python
1
star
82

idmclient

client for USSO to macaroons bridge server
Go
1
star
83

mgomonitor

prometheus stats for gopkg.in/mgo.v2
Go
1
star
84

http

Juju wrapper for the standard go HTTP library.
Go
1
star
85

jknife

jknife are juju db surgery tools - this should only be used with direction of a Juju engineer
Go
1
star
86

jasp

CSS
1
star
87

jujuapidoc

Generate information on the Juju API
Go
1
star
88

juju-controller

A Juju controller charm
Python
1
star
89

jaaslibjs

JavaScript library for interacting with the JAAS services
JavaScript
1
star
90

naturalsort

Sort strings according to natural sort order.
Go
1
star
91

charm-developer-docs

Documenting how to write a Juju charm
Shell
1
star
92

lxc

Fork of lxd/lxc to add Juju specific tweaks
Go
1
star
93

romulus

Go
1
star
94

simplekv

A naive key-value store with multiple backends
Go
1
star
95

usso

Go
1
star
96

juju-process-docker

a plugin to allow juju to interface with docker
Go
1
star
97

charm-base-images

Shell
1
star
98

jaas-monitor

Monitor all your jaas models (prototype)
Shell
1
star
99

proxy

A golang type for grouping information about proxy variables.
Go
1
star
100

collections

Deque and set implementations
Go
1
star