~bigbes/ci-cacher

ref: 519ce411ce7e77bc46ba4eb12c4619c838b3f059 ci-cacher/cmd/errors.go -rw-r--r-- 563 bytes
519ce411 — Eugene Blikh Bump VERSION to 0.1.1 for tag a day ago
                                                                                
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
package cmd

import "errors"

// Sentinel errors recognized by Execute → exit code mapping.
//
// exists  → ErrNotFound  →  1
// download without --url, key missing → ErrMissNoFallback → 3
// any other error → 2
var (
	ErrNotFound       = errors.New("cacher: key not found")
	ErrMissNoFallback = errors.New("cacher: cache miss and no --url fallback")
)

func exitCodeFor(err error) int {
	switch {
	case err == nil:
		return 0
	case errors.Is(err, ErrNotFound):
		return 1
	case errors.Is(err, ErrMissNoFallback):
		return 3
	default:
		return 2
	}
}