Skip to content

Commit 95c6e7a

Browse files
authored
Merge pull request #23 from lainio/repare-major-release
Finalizin docs, API, error handlers for 1.0
2 parents 9b9a851 + ed98df4 commit 95c6e7a

29 files changed

+1425
-795
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# IDEs, etc.
22
.idea
3-
Session.vim*
3+
*.vim*
44
coverage.*
55

66
# Binaries for programs and plugins

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
### Version history
44

5+
##### 0.9.52
6+
- `err2.Stderr` helpers for `Catch/Handle` to direct auto-logging + snippets
7+
- `assert` package `Shorter` `Longer` helpers for automatic messages
8+
- `asserter` package remove deprecated slow reflection based funcs
9+
- cleanup and refactoring for sample apps
10+
511
##### 0.9.51
612
- `flag` package support to set `err2` and `assert` package configuration
713
- `err2.Catch` default mode is to log error
@@ -17,7 +23,7 @@
1723
handlers
1824

1925
##### 0.9.40
20-
- Significant performance boost for: `defer err2.Handle/Catch()`
26+
- Significant performance boost for: `defer err2.Handle/Catch()`
2127
- **3x faster happy path than the previous version, which is now equal to
2228
simplest `defer` function in the `err`-returning function** . (Please see
2329
the `defer` benchmarks in the `err2_test.go` and run `make bench_reca`)
@@ -67,7 +73,7 @@
6773
especially performance
6874
6975
##### 0.9.0
70-
- **Clean and simple API**
76+
- **Clean and simple API**
7177
- Removing deprecated functions:
7278
- Only `err2.Handle` for error returning functions
7379
- Only `err2.Catch` for function that doesn't return error

README.md

Lines changed: 27 additions & 30 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) {
28-
try.Out1(os.Remove(dst)).Logf("cleaning error")
22+
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,12 +119,14 @@ 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
131126
error-handling scenarios. And remember that you can have as many error handlers
132-
per function as you need.
127+
per function as you need, as well as you can chain error handling functions per
128+
`err2.Handle` that allows you to build new error handling middleware for your
129+
own purposes.
133130
134131
#### Error Stack Tracing
135132
@@ -248,7 +245,7 @@ notExist := try.Is(r2.err, plugin.ErrNotExist)
248245
happens: nearest `err2.Handle` gets it first.
249246
250247
These `try.Is` functions help cleanup mesh idiomatic Go, i.e. mixing happy and
251-
error path, leads to.
248+
error path, leads to.
252249
253250
For more information see the examples in the documentation of both functions.
254251
@@ -328,7 +325,7 @@ func TestWebOfTrustInfo(t *testing.T) {
328325
assert.SLen(common, 2)
329326

330327
wot := dave.WebOfTrustInfo(eve.Node) //<- this includes asserts as well!!
331-
// 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
332329
// test failures for this TestWebOfTrustInfo -test.
333330

334331
assert.Equal(0, wot.CommonInvider)
@@ -364,7 +361,7 @@ stack.**
364361
When you are using `err2` or `assert` packages, i.e., just importing them, you
365362
have an option to automatically support for err2 configuration flags through
366363
Go's standard `flag` package. See more information about err2 settings from
367-
[Error Stack Tracing](#error-stack-tracing) and [Asserters](#asserters).
364+
[Error Stack Tracing](#error-stack-tracing) and [Asserters](#asserters).
368365
369366
Now you can always deploy your applications and services with the simple
370367
end-user friendly error messages and no stack traces, **but you can switch them
@@ -421,10 +418,10 @@ support packages like `err2` and `glog` and their flags.
421418
```go
422419
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
423420
defer err2.Handle(&err)
424-
421+
425422
// NOTE! Very important. Adds support for std flag pkg users: glog, err2
426423
goflag.Parse()
427-
424+
428425
try.To(goflag.Set("logtostderr", "true"))
429426
handleViperFlags(cmd) // local helper with envs
430427
glog.CopyStandardLogTo("ERROR") // for err2
@@ -470,7 +467,7 @@ part of the algorithm itself.**
470467
**there are no performance penalty at all**. However, the mandatory use of the
471468
`defer` might prevent some code optimisations like function inlining. And still,
472469
we have cases where using the `err2` and `try` package simplify the algorithm so
473-
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
474471
benchmarks for `io.Copy` in the repo.**)
475472
476473
If you have a performance-critical use case, we always recommend you to write
@@ -527,14 +524,14 @@ Please see the full version history from [CHANGELOG](./CHANGELOG.md).
527524
528525
### Latest Release
529526
530-
##### 0.9.52
531-
- `err2.Stderr` helpers for `Catch/Handle` to direct auto-logging + snippets
532-
- `assert` package `Shorter` `Longer` helpers for automatic messages
533-
- `asserter` package remove deprecated slow reflection based funcs
534-
- cleanup and refactoring for sample apps
535-
536-
### Upcoming releases
537-
538-
##### 0.9.6
539-
- Continue removing unused parts and repairing for 1.0.0 release.
540-
- Always more and better documentation
527+
##### 1.0.0
528+
- **Finally! We are very happy, and thanks to all who have helped!**
529+
- Lots of documentation updates and cleanups for version 1.0.0
530+
- `Catch/Handle` take unlimited amount error handler functions
531+
- allows building e.g. error handling middlewares
532+
- this is major feature because it allows building helpers/add-ons
533+
- automatic outputs aren't overwritten by given args, only with `assert.Plain`
534+
- Minor API fixes to still simplify it:
535+
- remove exported vars, obsolete types and funcs from `assert` pkg
536+
- `Result2.Def2()` sets only `Val2`
537+
- technical refactorings: variadic function calls only in API level

0 commit comments

Comments
 (0)