diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2024-07-28 16:30:48 +0200 |
|---|---|---|
| committer | Martin Lehoux <martin@lehoux.net> | 2024-07-28 15:34:57 +0100 |
| commit | ddc31aa9355889d5d2abd7dc36034d15351e9364 (patch) | |
| tree | 13fabad496a1afea3828a29446e0c95edbf3947c /kcore | |
| parent | 49d8f6f1de8938c89585db4d7af3cc4e0dee9bf5 (diff) | |
feat(kcore): Add Assertv0.4.1
Diffstat (limited to 'kcore')
| -rw-r--r-- | kcore/error.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/kcore/error.go b/kcore/error.go index bbacbf6..fad5f3d 100644 --- a/kcore/error.go +++ b/kcore/error.go @@ -1,6 +1,9 @@ package kcore -import "fmt" +import ( + "errors" + "fmt" +) func Wrap(err error, msg string) error { return fmt.Errorf("%s: %w", msg, err) @@ -14,3 +17,15 @@ func Expect(err error, msg string) { panic(err) } } + +var ErrAssert = errors.New("assertion error") + +func Assert(cond bool, msg string) { + if !cond { + err := ErrAssert + if msg != "" { + err = fmt.Errorf("%w: %s", err, msg) + } + panic(err) + } +} |
