Skip to content

Commit a1bb857

Browse files
committed
CopyFile doc comments update, use long package names for sub-pkgs
1 parent 56741bc commit a1bb857

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

doc.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@
22
Package err2 provides three main functionality:
33
1. err2 package includes helper functions for error handling & automatic error
44
stack tracing
5-
2. try package is for error checking
6-
3. assert package is for design-by-contract and preconditions both for normal
7-
runtime and for testing
8-
9-
The traditional error handling idiom in Go is roughly akin to
10-
11-
if err != nil { return err }
12-
13-
which applied recursively.
5+
2. [github.com/lainio/err2/try] sub-package is for error checking
6+
3. [github.com/lainio/err2/assert] sub-package is for design-by-contract and
7+
preconditions both for normal runtime and for unit testing
148
159
The err2 package drives programmers to focus on error handling rather than
1610
checking errors. We think that checks should be so easy that we never forget
@@ -19,7 +13,7 @@ them. The CopyFile example shows how it works:
1913
// CopyFile copies source file to the given destination. If any error occurs it
2014
// returns error value describing the reason.
2115
func CopyFile(src, dst string) (err error) {
22-
// Add first error handler just to annotate the error properly.
16+
// Add first error handler is to catch and annotate the error properly.
2317
defer err2.Handle(&err)
2418
2519
// Try to open the file. If error occurs now, err will be
@@ -32,16 +26,18 @@ them. The CopyFile example shows how it works:
3226
// Try to create a file. If error occurs now, err will be annotated and
3327
// returned properly.
3428
w := try.To1(os.Create(dst))
35-
// Add error handler to clean up the destination file. Place it here that
36-
// the next deferred close is called before our Remove call.
29+
// Add error handler to clean up the destination file in case of
30+
// error. Handler fn is called only if there has been an error at the
31+
// following try.To check. We place it here that the next deferred
32+
// close is called before our Remove a file call.
3733
defer err2.Handle(&err, err2.Err(func(error) {
3834
os.Remove(dst)
3935
}))
4036
defer w.Close()
4137
4238
// Try to copy the file. If error occurs now, all previous error handlers
43-
// will be called in the reversed order. And final return error is
44-
// properly annotated in all the cases.
39+
// will be called in the reversed order. And a final error value is
40+
// properly annotated and returned in all the cases.
4541
try.To1(io.Copy(w, r))
4642
4743
// All OK, just return nil.
@@ -62,8 +58,9 @@ we can write
6258
6359
b := try.To1(io.ReadAll(r))
6460
65-
Note that [try.To] functions are as fast as if err != nil statements. Please see
66-
the try package documentation for more information about the error checks.
61+
Note that try.To functions are as fast as if err != nil statements. Please see
62+
the [github.com/lainio/err2/try] package documentation for more information
63+
about the error checks.
6764
6865
# Automatic Stack Tracing
6966

0 commit comments

Comments
 (0)