-
Notifications
You must be signed in to change notification settings - Fork 89
/
errors.go
32 lines (26 loc) · 888 Bytes
/
errors.go
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
27
28
29
30
31
32
// Copyright 2024 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package utils
import (
"fmt"
)
// RcPassthroughError indicates that a Juju plugin command exited with a
// non-zero exit code. This error is used to exit with the return code.
type RcPassthroughError struct {
Code int
}
// Error implements error.
func (e *RcPassthroughError) Error() string {
return fmt.Sprintf("subprocess encountered error code %v", e.Code)
}
// IsRcPassthroughError returns whether the error is an RcPassthroughError.
func IsRcPassthroughError(err error) bool {
_, ok := err.(*RcPassthroughError)
return ok
}
// NewRcPassthroughError creates an error that will have the code used at the
// return code from the cmd.Main function rather than the default of 1 if
// there is an error.
func NewRcPassthroughError(code int) error {
return &RcPassthroughError{code}
}