github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/jujud/agent/model/errors.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package model
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  
     9  	"github.com/juju/juju/api/lifeflag"
    10  )
    11  
    12  // ErrRemoved may be returned by some worker started from Manifolds to
    13  // indicate that the model under management no longer exists.
    14  var ErrRemoved = errors.New("model removed")
    15  
    16  // lifeFilter is used with the lifeflag manifolds -- which do not depend
    17  // on runFlag -- to return an error that will be trapped by IsFatal.
    18  func lifeFilter(err error) error {
    19  	cause := errors.Cause(err)
    20  	if cause == lifeflag.ErrNotFound {
    21  		return ErrRemoved
    22  	}
    23  	return err
    24  }
    25  
    26  // IsFatal will probably be helpful when configuring a dependency.Engine
    27  // to run the result of Manifolds.
    28  func IsFatal(err error) bool {
    29  	return errors.Cause(err) == ErrRemoved
    30  }
    31  
    32  // WorstError will probably be helpful when configuring a dependency.Engine
    33  // to run the result of Manifolds.
    34  func WorstError(err, _ error) error {
    35  	// Doesn't matter if there's only one fatal error.
    36  	return err
    37  }
    38  
    39  // IgnoreErrRemoved returns nil if passed an error caused by ErrRemoved,
    40  // and otherwise returns the original error.
    41  func IgnoreErrRemoved(err error) error {
    42  	cause := errors.Cause(err)
    43  	if cause == ErrRemoved {
    44  		return nil
    45  	}
    46  	return err
    47  }