/
exit.go
51 lines (43 loc) · 874 Bytes
/
exit.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
43
44
45
46
47
48
49
50
51
// Package cos provides common low-level types and utilities for all aistore projects.
/*
* Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
*/
package cos
import (
"flag"
"fmt"
"os"
"github.com/NVIDIA/aistore/cmn/nlog"
)
const fatalPrefix = "FATAL ERROR: "
func _exit(msg string) {
fmt.Fprintln(os.Stderr, msg)
os.Exit(1)
}
func Exitf(f string, a ...any) {
msg := fmt.Sprintf(fatalPrefix+f, a...)
_exit(msg)
}
// +log
func ExitLogf(f string, a ...any) {
msg := fmt.Sprintf(fatalPrefix+f, a...)
if flag.Parsed() {
nlog.ErrorDepth(1, msg+"\n")
nlog.Flush(nlog.ActExit)
}
_exit(msg)
}
func ExitLog(a ...any) {
msg := fatalPrefix + fmt.Sprint(a...)
if flag.Parsed() {
nlog.ErrorDepth(1, msg+"\n")
nlog.Flush(nlog.ActExit)
}
_exit(msg)
}
// +condition
func ExitAssertLog(cond bool, a ...any) {
if !cond {
ExitLog(a...)
}
}