Skip to content

Commit 15dcc61

Browse files
committed
keep sample short, clean spaces
1 parent 07c4a76 commit 15dcc61

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

README.md

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,19 @@ and propagation** like other modern programming languages: **Zig**, Rust, Swift,
1010
etc. `err2` isn't an exception handling library, but an entirely orthogonal
1111
package with Go's existing error handling mechanism.
1212

13-
```go
13+
```go
1414
func CopyFile(src, dst string) (err error) {
1515
defer err2.Handle(&err)
1616

17-
assert.NotEmpty(src)
18-
assert.NotEmpty(dst)
19-
2017
r := try.To1(os.Open(src))
2118
defer r.Close()
2219

23-
w, err := os.Create(dst)
24-
if err != nil {
25-
return fmt.Errorf("mixing traditional error checking: %w", err)
26-
}
20+
w := try.To1(os.Create(dst))
2721
defer err2.Handle(&err, err2.Err(func(error) {
2822
try.Out(os.Remove(dst)).Logf("cleaning error")
2923
}))
3024
defer w.Close()
25+
3126
try.To1(io.Copy(w, r))
3227
return nil
3328
}
@@ -88,7 +83,7 @@ little error handling. But most importantly, it doesn't help developers with
8883
> resilience. -- Gregor Hohpe
8984
9085
Automatic error propagation is crucial because it makes your code change
91-
tolerant. And, of course, it helps to make your code error-safe:
86+
tolerant. And, of course, it helps to make your code error-safe:
9287

9388
![Never send a human to do a machine's job](https://www.magicalquote.com/wp-content/uploads/2013/10/Never-send-a-human-to-do-a-machines-job.jpg)
9489

@@ -99,7 +94,7 @@ The err2 package is your automation buddy:
9994
line exactly similar as
10095
[Zig's `errdefer`](https://ziglang.org/documentation/master/#errdefer).
10196
2. It helps to check and transport errors to the nearest (the defer-stack) error
102-
handler.
97+
handler.
10398
3. It helps us use design-by-contract type preconditions.
10499
4. It offers automatic stack tracing for every error, runtime error, or panic.
105100
If you are familiar with Zig, the `err2` error traces are same as Zig's.
@@ -124,7 +119,7 @@ This is the simplest form of `err2` automatic error handler:
124119
```go
125120
func doSomething() (err error) {
126121
// below: if err != nil { return ftm.Errorf("%s: %w", CUR_FUNC_NAME, err) }
127-
defer err2.Handle(&err)
122+
defer err2.Handle(&err)
128123
```
129124
130125
See more information from `err2.Handle`'s documentation. It supports several
@@ -250,7 +245,7 @@ notExist := try.Is(r2.err, plugin.ErrNotExist)
250245
happens: nearest `err2.Handle` gets it first.
251246
252247
These `try.Is` functions help cleanup mesh idiomatic Go, i.e. mixing happy and
253-
error path, leads to.
248+
error path, leads to.
254249
255250
For more information see the examples in the documentation of both functions.
256251
@@ -330,7 +325,7 @@ func TestWebOfTrustInfo(t *testing.T) {
330325
assert.SLen(common, 2)
331326

332327
wot := dave.WebOfTrustInfo(eve.Node) //<- this includes asserts as well!!
333-
// And if there's violations during the test run they are reported as
328+
// And if there's violations during the test run they are reported as
334329
// test failures for this TestWebOfTrustInfo -test.
335330

336331
assert.Equal(0, wot.CommonInvider)
@@ -366,7 +361,7 @@ stack.**
366361
When you are using `err2` or `assert` packages, i.e., just importing them, you
367362
have an option to automatically support for err2 configuration flags through
368363
Go's standard `flag` package. See more information about err2 settings from
369-
[Error Stack Tracing](#error-stack-tracing) and [Asserters](#asserters).
364+
[Error Stack Tracing](#error-stack-tracing) and [Asserters](#asserters).
370365
371366
Now you can always deploy your applications and services with the simple
372367
end-user friendly error messages and no stack traces, **but you can switch them
@@ -423,10 +418,10 @@ support packages like `err2` and `glog` and their flags.
423418
```go
424419
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
425420
defer err2.Handle(&err)
426-
421+
427422
// NOTE! Very important. Adds support for std flag pkg users: glog, err2
428423
goflag.Parse()
429-
424+
430425
try.To(goflag.Set("logtostderr", "true"))
431426
handleViperFlags(cmd) // local helper with envs
432427
glog.CopyStandardLogTo("ERROR") // for err2
@@ -472,7 +467,7 @@ part of the algorithm itself.**
472467
**there are no performance penalty at all**. However, the mandatory use of the
473468
`defer` might prevent some code optimisations like function inlining. And still,
474469
we have cases where using the `err2` and `try` package simplify the algorithm so
475-
that it's faster than the return value if err != nil version. (**See the
470+
that it's faster than the return value if err != nil version. (**See the
476471
benchmarks for `io.Copy` in the repo.**)
477472
478473
If you have a performance-critical use case, we always recommend you to write
@@ -536,7 +531,7 @@ Please see the full version history from [CHANGELOG](./CHANGELOG.md).
536531
- allows building e.g. error handling middlewares
537532
- this is major feature because it allows building helpers/add-ons
538533
- automatic outputs aren't overwritten by given args, only with `assert.Plain`
539-
- Minor API fixes to still simplify it:
534+
- Minor API fixes to still simplify it:
540535
- remove exported vars, obsolete types and funcs from `assert` pkg
541536
- `Result2.Def2()` sets only Val2
542537
- technical refactorings: variadic function calls only in API level

0 commit comments

Comments
 (0)