Skip to content

Commit eadb338

Browse files
committed
package documentation
1 parent d82b72a commit eadb338

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

readme.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Package errorx provides error implementation and error-related utilities.
2+
//
3+
// Conventional approach towards errors in *Go* is quite limited.
4+
// The typical case implies an error being created at some point:
5+
//
6+
// return errors.New("now this is unfortunate")
7+
//
8+
// Then being passed along with a no-brainer:
9+
//
10+
// if err != nil {
11+
// return err
12+
// }
13+
//
14+
// And, finally, handled by printing it to the log file:
15+
//
16+
// log.Errorf("Error: %s", err)
17+
//
18+
// This approach is simple, but it is often not enough.
19+
// There is a need to add context information to error, to check or hide its properties.
20+
// If all else fails, it pays to have a stack trace printed along with error text.
21+
//
22+
// Syntax
23+
//
24+
// The code above could be modified in this fashion:
25+
//
26+
// return errorx.IllegalState.New("unfortunate")
27+
//
28+
// if err != nil {
29+
// return errorx.Decorate(err, "this could be so much better")
30+
// }
31+
//
32+
// log.Errorf("Error: %+v", err)
33+
//
34+
// Here errorx.Decorate is used to add more information,
35+
// and syntax like errorx.IsOfType can still be used to check the original error.
36+
// This error also holds a stack trace captured at the point of creation.
37+
// With errorx syntax, any of this may be customized: stack trace omitted, error type hidden.
38+
// Type can be further customized with Traits, and error with Properties.
39+
// Package provide a utility functions to compose, switch over, check, and ignore errors based on their types and properties.
40+
//
41+
// See documentation for Error, Type and Namespace for more details.
42+
package errorx

0 commit comments

Comments
 (0)