diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-02 15:09:37 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-02 15:09:37 +0000 |
commit | 1bdf79827c623cc92504223a1085f366115bbb3d (patch) | |
tree | 80ed68ac6c4fcb59bdd4735120da8e241f7f99a2 /workhorse/internal/zipartifacts/errors.go | |
parent | 21e08b6197f192c983f8527f4bba1f2aaec8abf2 (diff) | |
download | gitlab-ce-1bdf79827c623cc92504223a1085f366115bbb3d.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'workhorse/internal/zipartifacts/errors.go')
-rw-r--r-- | workhorse/internal/zipartifacts/errors.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/workhorse/internal/zipartifacts/errors.go b/workhorse/internal/zipartifacts/errors.go new file mode 100644 index 00000000000..162816618f8 --- /dev/null +++ b/workhorse/internal/zipartifacts/errors.go @@ -0,0 +1,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] +} |