~bigbes/ci-cacher

ref: 63e1653aea40a9dca690f49bd8017e72c867d61b ci-cacher/cmd/errors.go -rw-r--r-- 563 bytes
63e1653a — Eugene Blikh Add builds.sr.ht CI: unit, e2e, and tag-only publish 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
	}
}