@@ -14,40 +14,42 @@ type (
14
14
Handler = handler.ErrorFn
15
15
)
16
16
17
+ // Sentinel error value helpers. They are convenient thanks to [try.IsNotFound]
18
+ // and similar functions.
19
+ //
20
+ // [ErrNotFound] ... [ErrNotEnabled] are similar no-error like [io.EOF] for
21
+ // those who really want to use error return values to transport non errors.
22
+ // It's far better to have discriminated unions as errors for function calls.
23
+ // But if you insist the related helpers are in they [try] package:
24
+ // try.IsNotFound, ...
25
+ //
26
+ // [ErrRecoverable] and [ErrNotRecoverable] since Go 1.20 wraps multiple errors
27
+ // same time, i.e. wrapped errors aren't list anymore but tree. This allows mark
28
+ // multiple semantics to same error. These error are mainly for that purpose.
17
29
var (
18
- // ErrNotFound is similar *no-error* like io.EOF for those who really want to
19
- // use error return values to transport non errors. It's far better to have
20
- // discriminated unions as errors for function calls. But if you insist the
21
- // related helpers are in they try package: try.IsNotFound(), ... These
22
- // 'global' errors and their helper functions in try package are for
23
- // experimenting now.
24
- ErrNotFound = errors .New ("not found" )
25
- ErrNotExist = errors .New ("not exist" )
26
- ErrAlreadyExist = errors .New ("already exist" )
27
- ErrNotAccess = errors .New ("permission denied" )
28
- ErrNotEnabled = errors .New ("not enabled" )
29
-
30
- // Since Go 1.20 wraps multiple errors same time, i.e. wrapped errors
31
- // aren't list anymore but tree. This allows mark multiple semantics to
32
- // same error. These error are mainly for that purpose.
30
+ ErrNotFound = errors .New ("not found" )
31
+ ErrNotExist = errors .New ("not exist" )
32
+ ErrAlreadyExist = errors .New ("already exist" )
33
+ ErrNotAccess = errors .New ("permission denied" )
34
+ ErrNotEnabled = errors .New ("not enabled" )
33
35
ErrNotRecoverable = errors .New ("cannot recover" )
34
36
ErrRecoverable = errors .New ("recoverable" )
35
-
36
- // Stdnull implements io.Writer that writes nothing, e.g.,
37
- // [SetLogTracer] in cases you don't want to use automatic log writer,
38
- // i.e., [LogTracer] == /dev/null. It can be used to change how the Catch
39
- // works, e.g., in CLI apps.
40
- Stdnull = & nullDev {}
41
37
)
42
38
39
+ // Stdnull implements [io.Writer] that writes nothing, e.g.,
40
+ // [SetLogTracer] in cases you don't want to use automatic log writer,
41
+ // i.e., [LogTracer] == /dev/null. It can be used to change how the [Catch]
42
+ // works, e.g., in CLI apps.
43
+ var Stdnull = & nullDev {}
44
+
43
45
// Handle is the general purpose error handling function. What makes it so
44
46
// convenient is its ability to handle all error handling cases:
45
47
// - just return the error value to caller
46
48
// - annotate the error value
47
49
// - execute real error handling like cleanup and releasing resources.
48
50
//
49
- // There is no performance penalty. The handler is called only when err != nil.
50
- // There is no limit how many Handle functions can be added to defer stack. They
51
+ // There's no performance penalty. The handler is called only when err != nil.
52
+ // There's no limit how many Handle functions can be added to defer stack. They
51
53
// all are called if an error has occurred.
52
54
//
53
55
// The function has an automatic mode where errors are annotated by function
58
60
//
59
61
// Note. If you are still using sentinel errors you must be careful with the
60
62
// automatic error annotation because it uses wrapping. If you must keep the
61
- // error value got from error checks: ' try.To(..)' , you must disable automatic
63
+ // error value got from error checks: [ try.To] , you must disable automatic
62
64
// error annotation (%w), or set the returned error values in the handler
63
65
// function. Disabling can be done by setting second argument nil:
64
66
//
@@ -112,10 +114,10 @@ func Handle(err *error, a ...any) {
112
114
113
115
// Catch is a convenient helper to those functions that doesn't return errors.
114
116
// Note, that Catch always catch the panics. If you don't want to stop them
115
- // (recover) you should add panic handler and continue panicking there. There
116
- // can be only one deferred Catch function per non error returning function like
117
- // main(). There is several ways to use the Catch function. And always remember
118
- // the defer.
117
+ // (i.e., use of [ recover] ) you should add panic handler and continue panicking
118
+ // there. There can be only one deferred Catch function per non error returning
119
+ // function like main(). There is several ways to use the Catch function. And
120
+ // always remember the [ defer] .
119
121
//
120
122
// The deferred Catch is very convenient, because it makes your current
121
123
// goroutine panic and error-safe. You can fine tune its 'global' behavior with
0 commit comments