-
Notifications
You must be signed in to change notification settings - Fork 492
/
stopped.go
34 lines (28 loc) · 880 Bytes
/
stopped.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
33
34
// Copyright 2019 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package multiwatcher
import (
"github.com/juju/errors"
)
// stopped represents an error when state is supported.
type stopped struct {
errors.Err
}
// ErrStoppedf returns an error which satisfies IsErrStopped().
func ErrStoppedf(format string, args ...interface{}) error {
newErr := errors.NewErr(format+" was stopped", args...)
newErr.SetLocation(2)
return &stopped{newErr}
}
// NewErrStopped returns an error which wraps err and satisfies IsErrStopped().
func NewErrStopped() error {
newErr := errors.NewErr("watcher was stopped")
newErr.SetLocation(2)
return &stopped{newErr}
}
// IsErrStopped reports whether the error was created with ErrStoppedf() or NewErrStopped().
func IsErrStopped(err error) bool {
err = errors.Cause(err)
_, ok := err.(*stopped)
return ok
}