1
// Copyright 2016 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
"github.com/juju/errors"
9
"github.com/juju/juju/worker/dependency"
10
"github.com/juju/juju/worker/lifeflag"
13
// ErrRemoved may be returned by some worker started from Manifolds to
14
// indicate that the model under management no longer exists.
15
var ErrRemoved = errors.New("model removed")
17
// LifeFilter is used with the lifeflag manifolds -- which do not depend
18
// on runFlag -- to return appropriate errors for consumption by the
19
// enclosing dependency.Engine (and/or its IsFatal check).
20
func LifeFilter(err error) error {
21
cause := errors.Cause(err)
23
case lifeflag.ErrNotFound:
25
case lifeflag.ErrValueChanged:
26
return dependency.ErrBounce
31
// IsFatal will probably be helpful when configuring a dependency.Engine
32
// to run the result of Manifolds.
33
func IsFatal(err error) bool {
34
return errors.Cause(err) == ErrRemoved
37
// WorstError will probably be helpful when configuring a dependency.Engine
38
// to run the result of Manifolds.
39
func WorstError(err, _ error) error {
40
// Doesn't matter if there's only one fatal error.
44
// IgnoreErrRemoved returns nil if passed an error caused by ErrRemoved,
45
// and otherwise returns the original error.
46
func IgnoreErrRemoved(err error) error {
47
cause := errors.Cause(err)
48
if cause == ErrRemoved {