1
// Copyright 2012-2015 Canonical Ltd.
1
// Copyright 2012-2016 Canonical Ltd.
2
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
10
"github.com/juju/errors"
10
11
"gopkg.in/juju/charm.v6-unstable"
11
12
"gopkg.in/mgo.v2/txn"
14
"github.com/juju/juju/network"
14
17
// ErrCharmAlreadyUploaded is returned by UpdateUploadedCharm() when
54
57
return errors.Trace(txnErr)
60
// ErrProviderIDNotUnique is a standard error to indicate the value specified
61
// for a ProviderID field is not unique within the current model.
62
type ErrProviderIDNotUnique struct {
66
func (e *ErrProviderIDNotUnique) Error() string {
67
idList := strings.Join(e.duplicateIDs, ", ")
68
return fmt.Sprintf("ProviderID(s) not unique: %s", idList)
71
// NewProviderIDNotUniqueError returns an instance of ErrProviderIDNotUnique
72
// initialized with the given duplicate provider IDs.
73
func NewProviderIDNotUniqueError(providerIDs ...network.Id) error {
74
stringIDs := make([]string, len(providerIDs))
75
for i, providerID := range providerIDs {
76
stringIDs[i] = string(providerID)
78
return newProviderIDNotUniqueErrorFromStrings(stringIDs)
81
func newProviderIDNotUniqueErrorFromStrings(providerIDs []string) error {
82
return &ErrProviderIDNotUnique{
83
duplicateIDs: providerIDs,
87
// IsProviderIDNotUniqueError returns if the given error or its cause is
88
// ErrProviderIDNotUnique.
89
func IsProviderIDNotUniqueError(err interface{}) bool {
93
// In case of a wrapped error, check the cause first.
95
cause := errors.Cause(err.(error))
99
_, ok := value.(*ErrProviderIDNotUnique)
103
// ErrParentDeviceHasChildren is a standard error to indicate a network
104
// link-layer device cannot be removed because other existing devices refer to
105
// it as their parent.
106
type ErrParentDeviceHasChildren struct {
111
func (e *ErrParentDeviceHasChildren) Error() string {
112
return fmt.Sprintf("parent device %q has %d children", e.parentName, e.numChildren)
115
func newParentDeviceHasChildrenError(parentName string, numChildren int) error {
116
return &ErrParentDeviceHasChildren{
117
parentName: parentName,
118
numChildren: numChildren,
122
// IsParentDeviceHasChildrenError returns if the given error or its cause is
123
// ErrParentDeviceHasChildren.
124
func IsParentDeviceHasChildrenError(err interface{}) bool {
128
// In case of a wrapped error, check the cause first.
130
cause := errors.Cause(err.(error))
134
_, ok := value.(*ErrParentDeviceHasChildren)