Skip to content

Finalizin docs, API, error handlers for 1.0 #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 89 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
ca5c108
string Len assert benchmark
lainio Jan 22, 2024
10bd9be
documentation about auto-generated messages, better layout, etc.
lainio Jan 25, 2024
d077657
better documentation, rm not used function
lainio Jan 25, 2024
fd0a95f
given assert msg is concat to auto-generated msg
lainio Jan 26, 2024
41cda29
better documentation INil and INotNil
lainio Feb 10, 2024
2873776
rm not used func args (linter)
lainio Feb 10, 2024
c6b877a
*.vim
lainio Feb 12, 2024
a744f45
flag & TestMain info for SetDefault documentation
lainio Feb 13, 2024
6bbd852
remove assert.SetDefault
lainio Feb 13, 2024
b56f802
move all handlers from err2.go and add Handlers helper to handlers.go
lainio Feb 13, 2024
ca7e9a8
Handler type must be type alias
lainio Feb 14, 2024
bbf85b6
Handler must be a type alias, and keep it to handler pkg
lainio Feb 16, 2024
a0180d6
docs how to combine SetErrorTracer, etc. with Flags
lainio Feb 16, 2024
c7fec26
sample of using multiple error handlers in one err2.Handle
lainio Feb 16, 2024
1bff1fc
sample how to combine SetLogTracer and flag.Parse to have runtime flags
lainio Feb 16, 2024
7920fdf
documentation note that you can use Flag pkg with SetXxxTracers
lainio Feb 16, 2024
4a30688
HandlerFn renames & support for multiple handler functions
lainio Feb 16, 2024
314344a
Handler multi call moved to internal/handler pkg with tests
lainio Feb 16, 2024
dfde0a4
documentation to sample
lainio Feb 16, 2024
097ce05
fixing bugs from prebuilt error handlers
lainio Feb 16, 2024
ddb444c
no use variadic expanse in internals
lainio Feb 17, 2024
6a2ea35
internal variadic -> slices
lainio Feb 17, 2024
7087dd6
new stream Copy benchmark
lainio Feb 18, 2024
34754a3
Merge branch 'internal-variadic-removal' into repare-major-release
lainio Feb 18, 2024
d808c9b
typos in assert message
lainio Feb 18, 2024
a8e9077
multiple error handlers documentation to Handle/Catch
lainio Feb 18, 2024
7dc62cc
update README files for 1.0.0
lainio Feb 18, 2024
598fd73
ioutil -> io
lainio Feb 19, 2024
8f4e835
not used ascii removed
lainio Feb 19, 2024
dee8182
string Longer/Shorter cross bug fixed
lainio Feb 19, 2024
9c7c414
pkg lvl documentations for err2, assert, and try
lainio Feb 19, 2024
fb152fa
real multi-handler call stack parsing test added
lainio Feb 20, 2024
12db281
split FuncName to allow easy fast debugging
lainio Feb 20, 2024
67cff84
implement&test for auto-annotation for multi-handler API
lainio Feb 20, 2024
c9da721
sample how to use init() with flag defaults for err2
lainio Feb 20, 2024
45fa921
multi-handler & auto-annotation documentation to Handle
lainio Feb 20, 2024
313e26d
Handle examples for multi-handler and annotation
lainio Feb 20, 2024
4f2b63f
Std streams output funcs NoReset-versions
lainio Feb 20, 2024
874d11f
comment of control flow assertions
lainio Feb 28, 2024
4ee44c4
bug fixed, reset the error, now doesn't
lainio Mar 1, 2024
ad70547
fix documentation
lainio Mar 1, 2024
a7a9a13
use org file copy and more samples
lainio Mar 1, 2024
abdb34e
english
lainio Mar 9, 2024
1b8c72d
Result2 Def1 & Def2 are two separated now
lainio Mar 9, 2024
ff0f65c
SetLogTrace docs: setting affects to all logging supporting function
lainio Mar 9, 2024
1aeaa32
fix: Plain assert allows override assert msg
lainio Mar 10, 2024
8ab9b40
rm 'That: ' from That and ThatNot asserter functions
lainio Mar 10, 2024
5a5806e
use handler pkg's ErrorFn
lainio Mar 11, 2024
c2eec00
documentation of using isErrorOnly
lainio Mar 11, 2024
7d66b3d
better docs for panic handler in Handle
lainio Mar 11, 2024
e0eec58
release comments of API changes
lainio Mar 11, 2024
809b9aa
wrong number strings to bad number
lainio Mar 13, 2024
bbf72e7
update documentation
lainio Mar 13, 2024
a308c3e
rm exported asserters + rename, some documentation update
lainio Mar 13, 2024
4202c60
rm exported types and fix documentation according & export fns
lainio Mar 13, 2024
4e2a07a
update v1.0.0 release comments
lainio Mar 14, 2024
a9a9c89
docs cleaned and simplify, remove wordiness
lainio Mar 14, 2024
4550b2e
readability of the assert pkg main doc
lainio Mar 15, 2024
efed678
more docs to Plain, Prod, and Dev
lainio Mar 15, 2024
aafd5de
move asserter constant's documentation above of section: go doc way
lainio Mar 15, 2024
316ba86
adding links to assert pkg
lainio Mar 15, 2024
8ab23ac
use hyperlinks in go docs
lainio Mar 16, 2024
089db87
hyperlinks in docs
lainio Mar 16, 2024
474ff2c
start hyperlinks for docs
lainio Mar 16, 2024
c9d5764
sentinel errors docs, and hyperlinks
lainio Mar 16, 2024
9ec0e64
err2 main doc's links
lainio Mar 16, 2024
1790aa0
more links
lainio Mar 16, 2024
cc31822
better message in example
lainio Mar 16, 2024
28018f4
shitload of links to docs
lainio Mar 16, 2024
c086eb1
real hyperlinks
lainio Mar 17, 2024
56741bc
add missing links to docs
lainio Mar 17, 2024
a1bb857
CopyFile doc comments update, use long package names for sub-pkgs
lainio Mar 17, 2024
b2d4af0
export because of the doc ref link
lainio Mar 17, 2024
2c48c35
better test case to use elsewhere
lainio Mar 17, 2024
c03ed81
sample code has wrong function
lainio Mar 17, 2024
7a1a1ed
missing helper comment in func Log doc
lainio Mar 17, 2024
bfd8dc5
continuing go doc format fixes, we are almost there
lainio Mar 17, 2024
fd2d889
update 1.0.0 release comment
lainio Mar 17, 2024
9b5e417
explain error return traces and add link to Zig
lainio Mar 17, 2024
08a533d
Note that with out comma
lainio Mar 18, 2024
a9218f2
Note that without comma, and updated docs
lainio Mar 18, 2024
bcca59e
assert pkg docs: sub-goroutines in unit tests, better English
lainio Mar 19, 2024
b189b5b
Push and Pop works for sub-goroutines + docs
lainio Mar 19, 2024
c2f1416
code block intention
lainio Mar 19, 2024
8073fd2
package lvl PushTester info for goroutines
lainio Mar 19, 2024
07c4a76
clean spaces
lainio Mar 19, 2024
15dcc61
keep sample short, clean spaces
lainio Mar 19, 2024
a8d6e30
fix some code block intentions
lainio Mar 20, 2024
ed98df4
finalize release 1.0.0 message
lainio Mar 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# IDEs, etc.
.idea
Session.vim*
*.vim*
coverage.*

# Binaries for programs and plugins
Expand Down
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

### Version history

##### 0.9.52
- `err2.Stderr` helpers for `Catch/Handle` to direct auto-logging + snippets
- `assert` package `Shorter` `Longer` helpers for automatic messages
- `asserter` package remove deprecated slow reflection based funcs
- cleanup and refactoring for sample apps

##### 0.9.51
- `flag` package support to set `err2` and `assert` package configuration
- `err2.Catch` default mode is to log error
Expand All @@ -17,7 +23,7 @@
handlers

##### 0.9.40
- Significant performance boost for: `defer err2.Handle/Catch()`
- Significant performance boost for: `defer err2.Handle/Catch()`
- **3x faster happy path than the previous version, which is now equal to
simplest `defer` function in the `err`-returning function** . (Please see
the `defer` benchmarks in the `err2_test.go` and run `make bench_reca`)
Expand Down Expand Up @@ -67,7 +73,7 @@
especially performance

##### 0.9.0
- **Clean and simple API**
- **Clean and simple API**
- Removing deprecated functions:
- Only `err2.Handle` for error returning functions
- Only `err2.Catch` for function that doesn't return error
Expand Down
57 changes: 27 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,19 @@ and propagation** like other modern programming languages: **Zig**, Rust, Swift,
etc. `err2` isn't an exception handling library, but an entirely orthogonal
package with Go's existing error handling mechanism.

```go
```go
func CopyFile(src, dst string) (err error) {
defer err2.Handle(&err)

assert.NotEmpty(src)
assert.NotEmpty(dst)

r := try.To1(os.Open(src))
defer r.Close()

w, err := os.Create(dst)
if err != nil {
return fmt.Errorf("mixing traditional error checking: %w", err)
}
w := try.To1(os.Create(dst))
defer err2.Handle(&err, err2.Err(func(error) {
try.Out1(os.Remove(dst)).Logf("cleaning error")
try.Out(os.Remove(dst)).Logf("cleaning error")
}))
defer w.Close()

try.To1(io.Copy(w, r))
return nil
}
Expand Down Expand Up @@ -88,7 +83,7 @@ little error handling. But most importantly, it doesn't help developers with
> resilience. -- Gregor Hohpe

Automatic error propagation is crucial because it makes your code change
tolerant. And, of course, it helps to make your code error-safe:
tolerant. And, of course, it helps to make your code error-safe:

![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)

Expand All @@ -99,7 +94,7 @@ The err2 package is your automation buddy:
line exactly similar as
[Zig's `errdefer`](https://ziglang.org/documentation/master/#errdefer).
2. It helps to check and transport errors to the nearest (the defer-stack) error
handler.
handler.
3. It helps us use design-by-contract type preconditions.
4. It offers automatic stack tracing for every error, runtime error, or panic.
If you are familiar with Zig, the `err2` error traces are same as Zig's.
Expand All @@ -124,12 +119,14 @@ This is the simplest form of `err2` automatic error handler:
```go
func doSomething() (err error) {
// below: if err != nil { return ftm.Errorf("%s: %w", CUR_FUNC_NAME, err) }
defer err2.Handle(&err)
defer err2.Handle(&err)
```

See more information from `err2.Handle`'s documentation. It supports several
error-handling scenarios. And remember that you can have as many error handlers
per function as you need.
per function as you need, as well as you can chain error handling functions per
`err2.Handle` that allows you to build new error handling middleware for your
own purposes.

#### Error Stack Tracing

Expand Down Expand Up @@ -248,7 +245,7 @@ notExist := try.Is(r2.err, plugin.ErrNotExist)
happens: nearest `err2.Handle` gets it first.

These `try.Is` functions help cleanup mesh idiomatic Go, i.e. mixing happy and
error path, leads to.
error path, leads to.

For more information see the examples in the documentation of both functions.

Expand Down Expand Up @@ -328,7 +325,7 @@ func TestWebOfTrustInfo(t *testing.T) {
assert.SLen(common, 2)

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

assert.Equal(0, wot.CommonInvider)
Expand Down Expand Up @@ -364,7 +361,7 @@ stack.**
When you are using `err2` or `assert` packages, i.e., just importing them, you
have an option to automatically support for err2 configuration flags through
Go's standard `flag` package. See more information about err2 settings from
[Error Stack Tracing](#error-stack-tracing) and [Asserters](#asserters).
[Error Stack Tracing](#error-stack-tracing) and [Asserters](#asserters).

Now you can always deploy your applications and services with the simple
end-user friendly error messages and no stack traces, **but you can switch them
Expand Down Expand Up @@ -421,10 +418,10 @@ support packages like `err2` and `glog` and their flags.
```go
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
defer err2.Handle(&err)

// NOTE! Very important. Adds support for std flag pkg users: glog, err2
goflag.Parse()

try.To(goflag.Set("logtostderr", "true"))
handleViperFlags(cmd) // local helper with envs
glog.CopyStandardLogTo("ERROR") // for err2
Expand Down Expand Up @@ -470,7 +467,7 @@ part of the algorithm itself.**
**there are no performance penalty at all**. However, the mandatory use of the
`defer` might prevent some code optimisations like function inlining. And still,
we have cases where using the `err2` and `try` package simplify the algorithm so
that it's faster than the return value if err != nil version. (**See the
that it's faster than the return value if err != nil version. (**See the
benchmarks for `io.Copy` in the repo.**)

If you have a performance-critical use case, we always recommend you to write
Expand Down Expand Up @@ -527,14 +524,14 @@ Please see the full version history from [CHANGELOG](./CHANGELOG.md).

### Latest Release

##### 0.9.52
- `err2.Stderr` helpers for `Catch/Handle` to direct auto-logging + snippets
- `assert` package `Shorter` `Longer` helpers for automatic messages
- `asserter` package remove deprecated slow reflection based funcs
- cleanup and refactoring for sample apps

### Upcoming releases

##### 0.9.6
- Continue removing unused parts and repairing for 1.0.0 release.
- Always more and better documentation
##### 1.0.0
- **Finally! We are very happy, and thanks to all who have helped!**
- Lots of documentation updates and cleanups for version 1.0.0
- `Catch/Handle` take unlimited amount error handler functions
- allows building e.g. error handling middlewares
- this is major feature because it allows building helpers/add-ons
- automatic outputs aren't overwritten by given args, only with `assert.Plain`
- Minor API fixes to still simplify it:
- remove exported vars, obsolete types and funcs from `assert` pkg
- `Result2.Def2()` sets only `Val2`
- technical refactorings: variadic function calls only in API level
Loading