forked from UbuntuEvangelist/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
55 lines (46 loc) · 1.44 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2012-2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package state
import (
"fmt"
"github.com/juju/errors"
"gopkg.in/juju/charm.v6-unstable"
"gopkg.in/mgo.v2/txn"
)
// ErrCharmAlreadyUploaded is returned by UpdateUploadedCharm() when
// the given charm is already uploaded and marked as not pending in
// state.
type ErrCharmAlreadyUploaded struct {
curl *charm.URL
}
func (e *ErrCharmAlreadyUploaded) Error() string {
return fmt.Sprintf("charm %q already uploaded", e.curl)
}
// IsCharmAlreadyUploadedError returns if the given error is
// ErrCharmAlreadyUploaded.
func IsCharmAlreadyUploadedError(err interface{}) bool {
if err == nil {
return false
}
// In case of a wrapped error, check the cause first.
value := err
cause := errors.Cause(err.(error))
if cause != nil {
value = cause
}
_, ok := value.(*ErrCharmAlreadyUploaded)
return ok
}
// ErrCharmRevisionAlreadyModified is returned when a pending or
// placeholder charm is no longer pending or a placeholder, signaling
// the charm is available in state with its full information.
var ErrCharmRevisionAlreadyModified = fmt.Errorf("charm revision already modified")
var ErrDead = fmt.Errorf("not found or dead")
var errNotAlive = fmt.Errorf("not found or not alive")
func onAbort(txnErr, err error) error {
if txnErr == txn.ErrAborted ||
errors.Cause(txnErr) == txn.ErrAborted {
return errors.Trace(err)
}
return errors.Trace(txnErr)
}