Skip to content

Commit b8b33e4

Browse files
committed
continue combine readme docs
1 parent fd7b890 commit b8b33e4

File tree

1 file changed

+68
-36
lines changed

1 file changed

+68
-36
lines changed

README.md

Lines changed: 68 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,17 @@ own purposes.
147147
148148
#### Error Stack Tracing
149149
150-
The err2 offers optional stack tracing. It's automatic and optimized. Optimized
151-
means that the call stack is processed before output. That means that stack
152-
trace starts from where the actual error/panic is occurred, not where the error
153-
is caught. You don't need to search for the line where the pointer was nil or
154-
received an error. That line is in the first one you are seeing:
150+
The err2 offers optional stack tracing. It's *automatic* and *optimized*.
155151
156152
<details>
157153
<summary>The example of the optimized call stack:</summary>
158154
155+
Optimized means that the call stack is processed before output. That means that
156+
stack trace *starts from where the actual error/panic is occurred*, not where
157+
the error or panic is caught. You don't need to search for the line where the
158+
pointer was nil or received an error. That line is in the first one you are
159+
seeing:
160+
159161
```sh
160162
---
161163
runtime error: index out of range [0] with length 0
@@ -214,38 +216,52 @@ but not without an error handler (`err2.Handle`). However, you can put your
214216
error handlers where ever you want in your call stack. That can be handy in the
215217
internal packages and certain types of algorithms.
216218
219+
<details>
220+
<summary>Immediate Error Handling Options</summary>
221+
<br/>
222+
217223
In cases where you want to handle the error immediately after the function call
218-
return you can use Go's default `if` statement. However, we encourage you to use
219-
the `errdefer` concept, `defer err2.Handle(&err)` for all of your error
220-
handling.
224+
return you can use Go's default `if` statement. However, `defer err2.Handle(&err)`
225+
for all of your error handling.
221226
222227
Nevertheless, there might be cases where you might want to:
223228
1. Suppress the error and use some default value.
229+
```go
230+
b := try.Out1(strconv.Atoi(s)).Catch(100)
231+
```
224232
1. Just write logging output and continue without breaking the execution.
233+
```go
234+
b := try.Out1(strconv.Atoi(s)).Logf("%s => 100", s)
235+
```
225236
1. Annotate the specific error value even when you have a general error handler.
226-
1. You want to handle the specific error value, let's say, at the same line
227-
or statement.
228-
229-
The `err2/try` package offers other helpers based on the DSL concept
230-
where the DSL's domain is error-handling. It's based on functions `try.Out`,
231-
`try.Out1`, and `try.Out2`, which return instances of types `Result`, `Result1`,
232-
and `Result2`. The `try.Result` is similar to other programming languages,
233-
i.e., discriminated union. Please see more from its documentation.
234-
235-
Now we could have the following:
236-
237-
```go
238-
b := try.Out1(strconv.Atoi(s)).Logf("%s => 100", s).Catch(100)
239-
```
237+
You are already familiar with `try.To` functions. There's *fast* annotation
238+
versions `try.T` which can be used as shown below:
239+
```go
240+
b := try.T1(io.ReadAll(r))("cfg file read")
241+
// where original were, for example:
242+
b := try.To1(io.ReadAll(r))
243+
```
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.
249+
```go
250+
try.Out(doSomething()).Handle(ErrNotSoBad, err2.Reset).Handle("fatal")
251+
```
240252
241-
The previous statement tries to convert incoming string value `s`, but if it
242-
doesn't succeed, it writes a warning to logs and uses the default value (100).
243-
The logging result includes the original error message as well.
253+
The `err2/try` package offers other helpers based on the error-handling
254+
language/API. It's based on functions `try.Out`, `try.Out1`, and `try.Out2`,
255+
which return instances of types `Result`, `Result1`, and `Result2`. The
256+
`try.Result` is similar to other programming languages, i.e., discriminated
257+
union. Please see more from its documentation.
244258
245259
It's easy to see that panicking about the errors at the start of the development
246260
is far better than not checking errors at all. But most importantly, `err2/try`
247261
**keeps the code readable.**
248262
263+
</details>
264+
249265
#### Filters for non-errors like io.EOF
250266
251267
When error values are used to transport some other information instead of
@@ -275,17 +291,31 @@ For more information see the examples in the documentation of both functions.
275291
## Assertion
276292
277293
The `assert` package is meant to be used for *design-by-contract-* type of
278-
development where you set pre- and post-conditions for your functions. It's not
279-
meant to replace the normal error checking but speed up the incremental hacking
280-
cycle. The default mode is to return an `error` value that includes a formatted
281-
and detailed assertion violation message. A developer gets immediate and proper
282-
feedback, allowing cleanup of the code and APIs before the release.
294+
development where you set pre- and post-conditions for *all* of your functions,
295+
*including test functions*. These asserts are as fast as if-statements.
296+
297+
<details>
298+
<summary>Fast Clean Code</summary>
299+
<br/>
300+
301+
> [!IMPORTANT]
302+
> It works *both runtime and for tests.* And even better, same asserts work in
303+
> both running modes.
304+
305+
Asserts are not meant to replace the normal error checking but speed up the
306+
incremental hacking cycle like TDD. The default mode is to return an `error`
307+
value that includes a formatted and detailed assertion violation message. A
308+
developer gets immediate and proper feedback independently of the running mode,
309+
allowing very fast feedback cycles.
310+
311+
</details>
283312
284313
#### Asserters
285314
286315
The assert package offers a few pre-build *asserters*, which are used to
287-
configure how the assert package deals with assert violations. The line below
288-
exemplifies how the default asserter is set in the package.
316+
configure *how the assert package deals with assert violations*. The line below
317+
exemplifies how the default asserter is set in the package. (See the
318+
documentation for more information about asserters.)
289319
290320
```go
291321
assert.SetDefault(assert.Production)
@@ -325,7 +355,8 @@ automatic testing as well.
325355
326356
#### Assertion Package for Unit Testing
327357
328-
The same asserts can be used **and shared** during the unit tests.
358+
The same asserts can be used **and shared** during the unit tests over module
359+
boundaries.
329360
330361
<details>
331362
<summary>The unit test code example:</summary>
@@ -555,9 +586,10 @@ the err2 package.
555586
556587
## Support And Contributions
557588
558-
The package has been in experimental mode quite long time. Since the Go generics
559-
we are transiting towards more official mode. Currently we offer support by
560-
GitHub Discussions. Naturally, any issues and contributions are welcome as well!
589+
The package was in experimental mode quite long time. Since the Go generics we
590+
did transit to official mode. Currently we offer support by GitHub Issues and
591+
Discussions. Naturally, we appreciate all feedback and contributions are
592+
very welcome!
561593
562594
## Roadmap
563595

0 commit comments

Comments
 (0)