Skip to content

Commit e5113f1

Browse files
committed
better layouts & language proofing
1 parent 555ef4c commit e5113f1

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

README.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Simplest rule for err2 error handlers are:
130130
1. Use `err2.handle` functions different calling schemes to achieve needed
131131
behaviour. For example, without no extra arguments `err2.Handle`
132132
automatically annotates your errors by building annotations string from the
133-
function's current name: `doSomething → "do something"`. Default is decamel
133+
function's current name: `doSomething → "do something:"`. Default is decamel
134134
and add spaces. See `err2.SetFormatter` for more information.
135135
1. Every function which uses err2 for error-checking should have at least one
136136
error handler. The current function panics if there are no error handlers and
@@ -139,7 +139,7 @@ Simplest rule for err2 error handlers are:
139139
140140
See more information from `err2.Handle`'s documentation. It supports several
141141
error-handling scenarios. And remember that you can have as many error handlers
142-
per function as you need, as well as you can chain error handling functions per
142+
per function as you need. You can also chain error handling functions per
143143
`err2.Handle` that allows you to build new error handling middleware for your
144144
own purposes.
145145
@@ -151,14 +151,15 @@ The err2 offers optional stack tracing. It's *automatic* and *optimized*.
151151
152152
<details>
153153
<summary>The example of the optimized call stack:</summary>
154+
<br/>
154155
155156
Optimized means that the call stack is processed before output. That means that
156157
stack trace *starts from where the actual error/panic is occurred*, not where
157158
the error or panic is caught. You don't need to search for the line where the
158159
pointer was nil or received an error. That line is in the first one you are
159160
seeing:
160161
161-
```sh
162+
```
162163
---
163164
runtime error: index out of range [0] with length 0
164165
---
@@ -169,7 +170,7 @@ main.main()
169170
/home/.../go/src/github.com/lainio/ic/main.go:77 +0x248
170171
```
171172
172-
</details><br/>
173+
</details>
173174
174175
Just set the `err2.SetErrorTracer` or `err2.SetPanicTracer` to the stream you
175176
want traces to be written:
@@ -185,8 +186,8 @@ the most cases proper error messages are enough and panics are handled
185186
immediately by a programmer.
186187
187188
> [!NOTE]
188-
> Since v0.9.5 you can set these asserters through Go's standard flag package
189-
> just by adding `flag.Parse()` to your program. See more information from
189+
> Since v0.9.5 you can set *tracers* through Go's standard flag package just by
190+
> adding `flag.Parse()` call to your source code. See more information from
190191
> [Automatic Flags](#automatic-flags).
191192
192193
[Read the package documentation for more
@@ -221,17 +222,20 @@ internal packages and certain types of algorithms.
221222
<br/>
222223
223224
In cases where you want to handle the error immediately after the function call
224-
return you can use Go's default `if` statement. However, `defer err2.Handle(&err)`
225-
for all of your error handling.
225+
you can use Go's default `if` statement. However, we recommend you to use
226+
`defer err2.Handle(&err)` for all of your error handling, because it keeps your
227+
code modifiable, refactorable, and skimmable.
226228
227229
Nevertheless, there might be cases where you might want to:
228-
1. Suppress the error and use some default value.
230+
1. Suppress the error and use some default value. In next, use 100 if `Atoi`
231+
fails:
229232
```go
230233
b := try.Out1(strconv.Atoi(s)).Catch(100)
231234
```
232-
1. Just write logging output and continue without breaking the execution.
235+
1. Just write logging output and continue without breaking the execution. In
236+
next, add log if `Atoi` fails.
233237
```go
234-
b := try.Out1(strconv.Atoi(s)).Logf("%s => 100", s)
238+
b := try.Out1(strconv.Atoi(s)).Logf("%s => 100", s).Catch(100)
235239
```
236240
1. Annotate the specific error value even when you have a general error handler.
237241
You are already familiar with `try.To` functions. There's *fast* annotation
@@ -241,11 +245,11 @@ Nevertheless, there might be cases where you might want to:
241245
// where original were, for example:
242246
b := try.To1(io.ReadAll(r))
243247
```
244-
1. You want to handle the specific error value, let's say, at the same line or
245-
statement. In below, the function `doSomething` returns an error value. If it
246-
returns `ErrNotSoBad`, we just suppress it. All the other errors are send to
247-
the current error handler and be handled there, but are annotated with
248-
'fatal' prefix before that.
248+
1. You want to handle the specific error value at the same line or statement. In
249+
below, the function `doSomething` returns an error value. If it returns
250+
`ErrNotSoBad`, we just suppress it. All the other errors are send to the
251+
current error handler and will be handled there, but are also annotated with
252+
'fatal' prefix before that here.
249253
```go
250254
try.Out(doSomething()).Handle(ErrNotSoBad, err2.Reset).Handle("fatal")
251255
```
@@ -388,7 +392,7 @@ of the actual Test function, **it's reported as a standard test failure.** That
388392
means we don't need to open our internal pre- and post-conditions just for
389393
testing.
390394
391-
</details><br/>
395+
</details>
392396
393397
**We can share the same assertions between runtime and test execution.**
394398

0 commit comments

Comments
 (0)