Skip to content

Commit 8fe8a79

Browse files
authored
Merge pull request #19 from lainio/issue-18
issue 18
2 parents 035a755 + 7b5af1d commit 8fe8a79

File tree

14 files changed

+388
-62
lines changed

14 files changed

+388
-62
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@ Please see the full version history from [CHANGELOG](./CHANGELOG.md).
430430
431431
### Latest Release
432432
433+
##### 0.9.41
434+
- Issue #18: **bug fixed**: noerr-handler had to be the last one of the err2
435+
handlers
436+
433437
##### 0.9.40
434438
- Significant performance boost for: `defer err2.Handle/Catch()`
435439
- **3x faster happy path than the previous version, which is now equal to

assert/assert.go

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,45 @@ import (
1616
type defInd = uint32
1717

1818
const (
19-
// Production is the best asserter for most uses. The assertion violations
20-
// are treated as Go error values. And only a pragmatic caller info is
21-
// automatically included into the error message like file name, line
22-
// number, and caller function.
19+
// Production (pkg default) is the best asserter for most uses. The
20+
// assertion violations are treated as Go error values. And only a
21+
// pragmatic caller info is automatically included into the error message
22+
// like file name, line number, and caller function, all in one line:
23+
//
24+
// copy file: main.go:37: CopyFile(): assertion violation: string shouldn't be empty
2325
Production defInd = 0 + iota
2426

2527
// Development is the best asserter for most development uses. The
2628
// assertion violations are treated as Go error values. And a formatted
2729
// caller info is automatically included to the error message like file
28-
// name, line number, and caller function.
30+
// name, line number, and caller function. Everything in a beautiful
31+
// multi-line message:
32+
//
33+
// --------------------------------
34+
// Assertion Fault at:
35+
// main.go:37 CopyFile():
36+
// assertion violation: string shouldn't be empty
37+
// --------------------------------
2938
Development
3039

3140
// Test minimalistic asserter for unit test use. More pragmatic is the
32-
// TestFull asserter (default).
41+
// TestFull asserter (test default).
3342
//
34-
// Use this asserter if your IDE/editor doesn't support long file names, or
35-
// for temporary problem solving for your programming environment.
43+
// Use this asserter if your IDE/editor doesn't support full file names and
44+
// it relies a relative path (Go standard). You can use this also if you
45+
// need temporary problem solving for your programming environment.
3646
Test
3747

38-
// TestFull asserter (default). The TestFull asserter includes caller info
39-
// and call stack for unit testing, similarly like err2's error traces.
48+
// TestFull asserter (test default). The TestFull asserter includes the
49+
// caller info and the call stack for unit testing, similarly like err2's
50+
// error traces.
4051
//
4152
// The call stack produced by the test asserts can be used over Go module
4253
// boundaries. For example, if your app and it's sub packages both use
4354
// err2/assert for unit testing and runtime checks, the runtime assertions
44-
// will be automatically converted to test asserts on the fly. If any of
45-
// the runtime asserts in sub packages fails during the app tests, the
46-
// current app test fails too.
55+
// will be automatically converted to test asserts. If any of the runtime
56+
// asserts of the sub packages fails during the app tests, the app test
57+
// fails as well.
4758
//
4859
// Note, that the cross-module assertions produce long file names (path
4960
// included), and some of the Go test result parsers cannot handle that.
@@ -53,7 +64,7 @@ const (
5364
TestFull
5465

5566
// Debug asserter transforms assertion violations to panics which is the
56-
// patter that e.g. Go's standard library uses:
67+
// pattern that e.g. Go's standard library uses:
5768
//
5869
// if p == nil {
5970
// panic("pkg: ptr cannot be nil")

assert/asserter.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ const (
4848
const officialTestOutputPrefix = " "
4949

5050
// NoImplementation always fails with no implementation.
51+
// Deprecated: use e.g. assert.NotImplemented(), only default asserter is used.
5152
func (asserter Asserter) NoImplementation(a ...any) {
5253
asserter.reportAssertionFault("not implemented", a...)
5354
}
5455

5556
// True asserts that term is true. If not it panics with the given formatting
5657
// string. Note! This and Truef are the most performant of all the assertion
5758
// functions.
59+
// Deprecated: use e.g. assert.That(), only default asserter is used.
5860
func (asserter Asserter) True(term bool, a ...any) {
5961
if !term {
6062
asserter.reportAssertionFault("assertion fault", a...)
@@ -63,6 +65,7 @@ func (asserter Asserter) True(term bool, a ...any) {
6365

6466
// Truef asserts that term is true. If not it panics with the given formatting
6567
// string.
68+
// Deprecated: use e.g. assert.That(), only default asserter is used.
6669
func (asserter Asserter) Truef(term bool, format string, a ...any) {
6770
if !term {
6871
if asserter.hasStackTrace() {
@@ -76,6 +79,7 @@ func (asserter Asserter) Truef(term bool, format string, a ...any) {
7679
// panics/errors (current Asserter) with the given msg. Note! This is very slow
7780
// (before we have generics). If you need performance use EqualInt. It's not so
7881
// convenient, though.
82+
// Deprecated: use e.g. assert.Len(), only default asserter is used.
7983
func (asserter Asserter) Len(obj any, length int, a ...any) {
8084
ok, l := getLen(obj)
8185
if !ok {
@@ -90,6 +94,7 @@ func (asserter Asserter) Len(obj any, length int, a ...any) {
9094

9195
// EqualInt asserts that integers are equal. If not it panics/errors (current
9296
// Asserter) with the given msg.
97+
// Deprecated: use e.g. assert.Equal(), only default asserter is used.
9398
func (asserter Asserter) EqualInt(val, want int, a ...any) {
9499
if want != val {
95100
defMsg := fmt.Sprintf("got %d, want %d", val, want)
@@ -101,13 +106,15 @@ func (asserter Asserter) EqualInt(val, want int, a ...any) {
101106
// panics/errors (current Asserter) with the given msg. Note! This is very slow
102107
// (before we have generics). If you need performance use EqualInt. It's not so
103108
// convenient, though.
109+
// Deprecated: use e.g. assert.Len(), only default asserter is used.
104110
func (asserter Asserter) Lenf(obj any, length int, format string, a ...any) {
105111
args := combineArgs(format, a)
106112
asserter.Len(obj, length, args...)
107113
}
108114

109115
// Empty asserts that length of the object is zero. If not it panics with the
110116
// given formatting string. Note! This is slow.
117+
// Deprecated: use e.g. assert.Empty(), only default asserter is used.
111118
func (asserter Asserter) Empty(obj any, msg ...any) {
112119
ok, l := getLen(obj)
113120
if !ok {
@@ -122,13 +129,15 @@ func (asserter Asserter) Empty(obj any, msg ...any) {
122129

123130
// NotEmptyf asserts that length of the object greater than zero. If not it
124131
// panics with the given formatting string. Note! This is slow.
132+
// Deprecated: use e.g. assert.NotEmpty(), only default asserter is used.
125133
func (asserter Asserter) NotEmptyf(obj any, format string, msg ...any) {
126134
args := combineArgs(format, msg)
127135
asserter.Empty(obj, args...)
128136
}
129137

130138
// NotEmpty asserts that length of the object greater than zero. If not it
131139
// panics with the given formatting string. Note! This is slow.
140+
// Deprecated: use e.g. assert.NotEmpty(), only default asserter is used.
132141
func (asserter Asserter) NotEmpty(obj any, msg ...any) {
133142
ok, l := getLen(obj)
134143
if !ok {

assert/goid_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
)
66

77
func TestGoid(t *testing.T) {
8+
t.Parallel()
89
stackBytes := []byte(`goroutine 518 [running]:
910
`)
1011

err2.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,18 @@ var (
6363
// an second argument:
6464
//
6565
// defer err2.Handle(&err, func(err error) error {
66-
// os.Remove(dst)
66+
// if rmErr := os.Remove(dst); rmErr != nil {
67+
// return fmt.Errorf("%w: cleanup error: %w", err, rmErr)
68+
// }
6769
// return err
6870
// })
6971
//
7072
// If you need to stop general panics in handler, you can do that by giving a
7173
// panic handler function:
7274
//
7375
// defer err2.Handle(&err,
74-
// err2.Err( func(error) { os.Remove(dst) }), // err2.Err keeps it short
75-
// func(p any) {} // panic handler, it's stops panics, you can re-throw
76+
// err2.Err( func(error) { os.Remove(dst) }), // err2.Err() keeps it short
77+
// func(p any) {} // <- handler stops panics, re-throw or not
7678
// )
7779
func Handle(err *error, a ...any) {
7880
// This and others are similar but we need to call `recover` here because

0 commit comments

Comments
 (0)