Welcome to mirror list, hosted at ThFree Co, Russian Federation.

errors.go « zipartifacts « internal « workhorse - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 162816618f854f811cf884ff78f2866c993c1e30 (plain)
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
52
53
54
55
56
57
package zipartifacts

import (
	"errors"
)

// These are exit codes used by subprocesses in cmd/gitlab-zip-xxx. We also use
// them to map errors and error messages that we use as label in Prometheus.
const (
	CodeNotZip = 10 + iota
	CodeEntryNotFound
	CodeArchiveNotFound
	CodeLimitsReached
	CodeUnknownError
)

var (
	ErrorCode = map[int]error{
		CodeNotZip:          errors.New("zip archive format invalid"),
		CodeEntryNotFound:   errors.New("zip entry not found"),
		CodeArchiveNotFound: errors.New("zip archive not found"),
		CodeLimitsReached:   errors.New("zip processing limits reached"),
		CodeUnknownError:    errors.New("zip processing unknown error"),
	}

	ErrorLabel = map[int]string{
		CodeNotZip:          "archive_invalid",
		CodeEntryNotFound:   "entry_not_found",
		CodeArchiveNotFound: "archive_not_found",
		CodeLimitsReached:   "limits_reached",
		CodeUnknownError:    "unknown_error",
	}

	ErrBadMetadata = errors.New("zip artifacts metadata invalid")
)

// ExitCodeByError find an os.Exit code for a corresponding error.
// CodeUnkownError in case it can not be found.
func ExitCodeByError(err error) int {
	for c, e := range ErrorCode {
		if err == e {
			return c
		}
	}

	return CodeUnknownError
}

// ErrorLabelByCode returns a Prometheus counter label associated with an exit code.
func ErrorLabelByCode(code int) string {
	label, ok := ErrorLabel[code]
	if ok {
		return label
	}

	return ErrorLabel[CodeUnknownError]
}