~bigbes/ci-cacher

ref: e8e2b2f17cf11feb30d2cfc6fd306d9dab1775c4 ci-cacher/cmd/errors.go -rw-r--r-- 563 bytes
e8e2b2f1 — Eugene Blikh Add docs/index.html landing page; publish.yml substitutes build info 2 days 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
	}
}