forked from NVIDIA/aistore
/
assert.go
42 lines (35 loc) · 842 Bytes
/
assert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Package cos provides common low-level types and utilities for all aistore projects.
/*
* Copyright (c) 2018-2021, NVIDIA CORPORATION. All rights reserved.
*/
package cos
import (
"fmt"
"github.com/artashesbalabekyan/aistore/3rdparty/glog"
)
const assertMsg = "assertion failed"
// NOTE: Not to be used in the datapath - consider instead one of the flavors below.
func Assertf(cond bool, f string, a ...any) {
if !cond {
AssertMsg(cond, fmt.Sprintf(f, a...))
}
}
func Assert(cond bool) {
if !cond {
glog.Flush()
panic(assertMsg)
}
}
// NOTE: when using Sprintf and such, `if (!cond) { AssertMsg(false, msg) }` is the preferable usage.
func AssertMsg(cond bool, msg string) {
if !cond {
glog.Flush()
panic(assertMsg + ": " + msg)
}
}
func AssertNoErr(err error) {
if err != nil {
glog.Flush()
panic(err)
}
}