-
Notifications
You must be signed in to change notification settings - Fork 8
/
error.go
41 lines (33 loc) · 886 Bytes
/
error.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
package io
import (
"fmt"
"os"
"runtime"
"strings"
)
const (
EXIT_SUCCESS = 0
EXIT_FAILURE = 1
)
func ExitWithMessage(err error) {
_, fn, line, _ := runtime.Caller(1)
cols := strings.Split(fn, "goalign/")
name := cols[len(cols)-1]
fmt.Fprintf(os.Stderr, "[Error] in %s (line %d), message: %v\n", name, line, err)
os.Exit(EXIT_FAILURE)
}
func PrintMessage(message string) {
_, fn, line, _ := runtime.Caller(1)
cols := strings.Split(fn, "goalign/")
name := cols[len(cols)-1]
fmt.Fprintf(os.Stderr, "[Warning] in %s (line %d), message: %s\n", name, line, message)
}
func PrintSimpleMessage(message string) {
fmt.Fprintf(os.Stderr, "%s\n", message)
}
func LogError(err error) {
_, fn, line, _ := runtime.Caller(1)
cols := strings.Split(fn, "goalign/")
name := cols[len(cols)-1]
fmt.Fprintf(os.Stderr, "[Error] in %s (line %d), message: %v\n", name, line, err)
}