File: fatal.go

package info (click to toggle)
restic 0.9.4%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 26,636 kB
  • sloc: sh: 1,460; makefile: 46; python: 35
file content (38 lines) | stat: -rw-r--r-- 965 bytes parent folder | download | duplicates (2)
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
package errors

import "fmt"

// fatalError is an error that should be printed to the user, then the program
// should exit with an error code.
type fatalError string

func (e fatalError) Error() string {
	return string(e)
}

func (e fatalError) Fatal() bool {
	return true
}

// Fataler is an error which should be printed to the user directly.
// Afterwards, the program should exit with an error.
type Fataler interface {
	Fatal() bool
}

// IsFatal returns true if err is a fatal message that should be printed to the
// user. Then, the program should exit.
func IsFatal(err error) bool {
	e, ok := err.(Fataler)
	return ok && e.Fatal()
}

// Fatal returns a wrapped error which implements the Fataler interface.
func Fatal(s string) error {
	return Wrap(fatalError(s), "Fatal")
}

// Fatalf returns an error which implements the Fataler interface.
func Fatalf(s string, data ...interface{}) error {
	return Wrap(fatalError(fmt.Sprintf(s, data...)), "Fatal")
}