Syntax coloring for Readme

I think it helps readability.
This commit is contained in:
Mustafa Akın 2016-05-09 11:42:59 +03:00 committed by Dave Cheney
parent 0d62637d04
commit 502e17a0cb

View File

@ -3,7 +3,7 @@
Package errors implements functions for manipulating errors. Package errors implements functions for manipulating errors.
The traditional error handling idiom in Go is roughly akin to The traditional error handling idiom in Go is roughly akin to
``` ```go
if err != nil { if err != nil {
return err return err
} }
@ -13,7 +13,7 @@ which applied recursively up the call stack results in error reports without con
## Adding context to an error ## Adding context to an error
The errors.Wrap function returns a new error that adds context to the original error. For example The errors.Wrap function returns a new error that adds context to the original error. For example
``` ```go
_, err := ioutil.ReadAll(r) _, err := ioutil.ReadAll(r)
if err != nil { if err != nil {
return errors.Wrap(err, "read failed") return errors.Wrap(err, "read failed")
@ -24,13 +24,13 @@ In addition, `errors.Wrap` records the file and line where it was called, allowi
## Retrieving the cause of an error ## Retrieving the cause of an error
Using `errors.Wrap` constructs a stack of errors, adding context to the preceding error. Depending on the nature of the error it may be necessary to recurse the operation of errors.Wrap to retrieve the original error for inspection. Any error value which implements this interface can be inspected by `errors.Cause`. Using `errors.Wrap` constructs a stack of errors, adding context to the preceding error. Depending on the nature of the error it may be necessary to recurse the operation of errors.Wrap to retrieve the original error for inspection. Any error value which implements this interface can be inspected by `errors.Cause`.
``` ```go
type causer interface { type causer interface {
Cause() error Cause() error
} }
``` ```
`errors.Cause` will recursively retrieve the topmost error which does not implement `causer`, which is assumed to be the original cause. For example: `errors.Cause` will recursively retrieve the topmost error which does not implement `causer`, which is assumed to be the original cause. For example:
``` ```go
switch err := errors.Cause(err).(type) { switch err := errors.Cause(err).(type) {
case *MyError: case *MyError:
// handle specifically // handle specifically