Skip to content

Commit 27d6cdb

Browse files
feat: add command for local code review (#226)
1 parent 5dc6dbc commit 27d6cdb

17 files changed

Lines changed: 2041 additions & 4 deletions

File tree

cmd/errors.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,41 @@ import (
77
"github.com/Use-Tusk/tusk-cli/internal/api"
88
)
99

10+
// ExitCodeError wraps an error with a specific process exit code. main.go
11+
// unwraps this to pick the right os.Exit value; without it, Cobra-returned
12+
// errors map to exit 1.
13+
type ExitCodeError struct {
14+
Code int
15+
Err error
16+
}
17+
18+
func (e *ExitCodeError) Error() string {
19+
if e == nil || e.Err == nil {
20+
return ""
21+
}
22+
return e.Err.Error()
23+
}
24+
25+
func (e *ExitCodeError) Unwrap() error {
26+
if e == nil {
27+
return nil
28+
}
29+
return e.Err
30+
}
31+
32+
// ExitCodeOf returns the exit code embedded in err (or any wrapper in its
33+
// chain), defaulting to 1 if none is present.
34+
func ExitCodeOf(err error) int {
35+
if err == nil {
36+
return 0
37+
}
38+
var ec *ExitCodeError
39+
if errors.As(err, &ec) {
40+
return ec.Code
41+
}
42+
return 1
43+
}
44+
1045
// formatApiError converts raw API errors into user-friendly messages with
1146
// actionable guidance. Non-API errors pass through unchanged.
1247
func formatApiError(err error) error {

0 commit comments

Comments
 (0)