README.md further improved
This commit is contained in:
parent
37acf646f4
commit
023b997cb1
16
README.md
16
README.md
@ -10,39 +10,39 @@ go get git.tordarus.net/tordarus/adverr
|
|||||||
|
|
||||||
## Usage examples
|
## Usage examples
|
||||||
|
|
||||||
### Importing
|
### Import
|
||||||
```go
|
```go
|
||||||
import "git.tordarus.net/tordarus/adverr"
|
import "git.tordarus.net/tordarus/adverr"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Creating error templates
|
### Create error templates
|
||||||
```go
|
```go
|
||||||
var (
|
var (
|
||||||
ErrDoStuffFailed = adverr.NewErrTmpl("ErrDoStuffFailed", "Could'nt do stuff because of %s")
|
ErrDoStuffFailed = adverr.NewErrTmpl("ErrDoStuffFailed", "Could'nt do stuff because of %s")
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Creating independent error (without error template)
|
### Create independent error (without error template)
|
||||||
```go
|
```go
|
||||||
func doStuffWithIndependentErr() error {
|
func doStuffWithIndependentErr() error {
|
||||||
return adverr.New("Could'nt do stuff")
|
return adverr.New("Could'nt do stuff")
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Creating error based on template
|
### Create error based on template
|
||||||
```go
|
```go
|
||||||
func doStuff() error {
|
func doStuff() error {
|
||||||
return ErrDoStuffFailed.New("reasons")
|
return ErrDoStuffFailed.New("reasons")
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Printing errors on stderr convieniently
|
### Print errors on stderr convieniently
|
||||||
```go
|
```go
|
||||||
adverr.Print(myErr)
|
adverr.Print(myErr)
|
||||||
adverr.Println(myErr)
|
adverr.Println(myErr)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Printing errors on stderr and exit with exit code
|
### Print errors on stderr and exit with exit code
|
||||||
```go
|
```go
|
||||||
adverr.Fatal(myErr, 1)
|
adverr.Fatal(myErr, 1)
|
||||||
adverr.Fatalln(myErr, 1)
|
adverr.Fatalln(myErr, 1)
|
||||||
@ -63,7 +63,7 @@ fmt.Println(err1 == err2) // false
|
|||||||
fmt.Println(err1.Error() == err2.Error()) // false
|
fmt.Println(err1.Error() == err2.Error()) // false
|
||||||
```
|
```
|
||||||
|
|
||||||
### Wrapping errors
|
### Wrap errors (Causality of errors)
|
||||||
By wrapping errors, you can provide an error that is caused by another error.
|
By wrapping errors, you can provide an error that is caused by another error.
|
||||||
A 'Caused by' section will be printed in the stack trace showing the original error.
|
A 'Caused by' section will be printed in the stack trace showing the original error.
|
||||||
You can also retrieve the original error by using `errors.Unwrap()`
|
You can also retrieve the original error by using `errors.Unwrap()`
|
||||||
@ -78,7 +78,7 @@ func doStuffWrapped() error {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Retrieving call stack trace (for debugging purposes)
|
### Retrieve call stack trace (for debugging purposes)
|
||||||
```go
|
```go
|
||||||
fmt.Println(adverr.Trace())
|
fmt.Println(adverr.Trace())
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user