-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,584 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package e5 | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type ( | ||
any = interface{} | ||
) | ||
|
||
var ( | ||
pt = fmt.Printf | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package e5 | ||
|
||
import ( | ||
"errors" | ||
"io" | ||
"testing" | ||
) | ||
|
||
var testErr error | ||
|
||
func BenchmarkHandleNil(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
err := func() (err error) { | ||
defer Handle(&err) | ||
return nil | ||
}() | ||
if err != nil { | ||
b.Fatal() | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkHandleErr(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
err := func() (err error) { | ||
defer Handle(&err) | ||
return io.EOF | ||
}() | ||
if !errors.Is(err, io.EOF) { | ||
b.Fatal() | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkHandleCheckNil(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
err := func() (err error) { | ||
defer Handle(&err) | ||
Check(nil) | ||
return | ||
}() | ||
if err != nil { | ||
b.Fatal() | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkHandleCheck(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
err := func() (err error) { | ||
defer Handle(&err) | ||
Check(io.EOF) | ||
return | ||
}() | ||
if !errors.Is(err, io.EOF) { | ||
b.Fatal() | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkHandleCheckDeep(b *testing.B) { | ||
var fn func(int) error | ||
fn = func(i int) (err error) { | ||
defer Handle(&err) | ||
if i == 0 { | ||
return io.EOF | ||
} | ||
Check(fn(i - 1)) | ||
return | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
err := fn(30) | ||
if !errors.Is(err, io.EOF) { | ||
b.Fatal() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package e5 | ||
|
||
// CheckFunc is the type of Check, see Check's doc for details | ||
type CheckFunc func(err error, args ...error) error | ||
|
||
// Check is for error checking. | ||
// if err is not nil, it will be wrapped by DefaultWrap then raised by Throw | ||
var Check = CheckFunc(func(err error, args ...error) error { | ||
if err == nil { | ||
return nil | ||
} | ||
err = Wrap.With(args...)(err) | ||
return Throw(err) | ||
}) | ||
|
||
// With returns a new CheckFunc that do additional wrapping with moreWraps | ||
func (c CheckFunc) With(moreArgs ...error) CheckFunc { | ||
return func(err error, args ...error) error { | ||
if err == nil { | ||
return nil | ||
} | ||
err = Wrap.With(args...)(err) | ||
return c(err, moreArgs...) | ||
} | ||
} | ||
|
||
var CheckWithStacktrace = Check.With(WrapStacktrace) |
Oops, something went wrong.