Skip to content

Commit c9d5764

Browse files
committed
sentinel errors docs, and hyperlinks
1 parent 474ff2c commit c9d5764

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

err2.go

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,42 @@ type (
1414
Handler = handler.ErrorFn
1515
)
1616

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.
1729
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")
3335
ErrNotRecoverable = errors.New("cannot recover")
3436
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{}
4137
)
4238

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+
4345
// Handle is the general purpose error handling function. What makes it so
4446
// convenient is its ability to handle all error handling cases:
4547
// - just return the error value to caller
4648
// - annotate the error value
4749
// - execute real error handling like cleanup and releasing resources.
4850
//
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
5153
// all are called if an error has occurred.
5254
//
5355
// The function has an automatic mode where errors are annotated by function
@@ -58,7 +60,7 @@ var (
5860
//
5961
// Note. If you are still using sentinel errors you must be careful with the
6062
// 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
6264
// error annotation (%w), or set the returned error values in the handler
6365
// function. Disabling can be done by setting second argument nil:
6466
//
@@ -112,10 +114,10 @@ func Handle(err *error, a ...any) {
112114

113115
// Catch is a convenient helper to those functions that doesn't return errors.
114116
// 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].
119121
//
120122
// The deferred Catch is very convenient, because it makes your current
121123
// goroutine panic and error-safe. You can fine tune its 'global' behavior with

0 commit comments

Comments
 (0)