Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

Commit 326e08f

Browse files
committed
godoc
1 parent d20a8b8 commit 326e08f

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# errors [![Travis-CI](https://travis-ci.org/pkg/errors.svg)](https://travis-ci.org/pkg/errors) [![GoDoc](https://godoc.org/github.com/pkg/errors?status.png)](http://godoc.org/github.com/pkg/errors)
22

3-
Read the [presentation](https://t.co/GGPr7HJZYR) to see what the big deal is, blog post coming next week.
3+
Would you like to know more? Read the [original presentation](https://t.co/GGPr7HJZYR), blog post coming soon.
44

55
Licence: MIT

errors.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,49 @@
11
// Package errors implements functions for manipulating errors.
2+
//
3+
// The tranditional error handling idiom in Go is roughly akin to
4+
//
5+
// if err != nil {
6+
// return err
7+
// }
8+
//
9+
// which applied recursively up the call stack results in error reports
10+
// without context or debugging information. The errors package allows
11+
// programmers to add context to the failure path in their code in a way
12+
// that does not destroy the original value of the error.
13+
//
14+
// Adding context to an error
15+
//
16+
// The errors.Wrap function returns a new error that adds context to the
17+
// original error. For example
18+
//
19+
// _, err := ioutil.ReadAll(r)
20+
// if err != nil {
21+
// return errors.Wrap(err, "read failed")
22+
//
23+
// In addition, errors.Wrap records the file and line where it was called,
24+
// allowing the programmer to retrieve the path to the original error.
25+
//
26+
// Retrieving the cause of an error
27+
//
28+
// Using errors.Wrap constructs a stack of errors, adding context to the
29+
// preceeding error. Depending on the nature of the error it may be necessary
30+
// to recerse the operation of errors.Wrap to retrieve the original error
31+
// for inspection. Any error value which implements this interface
32+
//
33+
// type causer interface {
34+
// Cause() error
35+
// }
36+
//
37+
// Can be inspected by errors.Cause which will recursively retrieve the topmost
38+
// error which does nor implement causer, which is assumed to be the original
39+
// cause. For example:
40+
//
41+
// switch err := errors.Cause(err).(type) {
42+
// case *MyError:
43+
// // handle specifically
44+
// default:
45+
// // unknown error
46+
// }
247
package errors
348

449
import (

0 commit comments

Comments
 (0)