forked from aws/amazon-ecs-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
89 lines (73 loc) · 2.63 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
package api
import (
"strings"
"github.com/aws/aws-sdk-go/aws/awserr"
)
// InstanceTypeChangedErrorMessage is the error message to print for the
// instance type changed error when registering a container instance
const InstanceTypeChangedErrorMessage = "Container instance type changes are not supported."
// IsInstanceTypeChangedError returns true if the error when
// registering the container instance is because of instance type being
// changed
func IsInstanceTypeChangedError(err error) bool {
if awserr, ok := err.(awserr.Error); ok {
return strings.Contains(awserr.Message(), InstanceTypeChangedErrorMessage)
}
return false
}
type badVolumeError struct {
msg string
}
func (err *badVolumeError) Error() string { return err.msg }
func (err *badVolumeError) ErrorName() string { return "InvalidVolumeError" }
func (err *badVolumeError) Retry() bool { return false }
type NamedError interface {
error
ErrorName() string
}
// DefaultNamedError is a wrapper type for 'error' which adds an optional name and provides a symmetric
// marshal/unmarshal
type DefaultNamedError struct {
Err string `json:"error"`
Name string `json:"name"`
}
// Error implements error
func (err *DefaultNamedError) Error() string {
if err.Name == "" {
return "UnknownError: " + err.Err
}
return err.Name + ": " + err.Err
}
// ErrorName implements NamedError
func (err *DefaultNamedError) ErrorName() string {
return err.Name
}
// NewNamedError creates a NamedError.
func NewNamedError(err error) *DefaultNamedError {
if namedErr, ok := err.(NamedError); ok {
return &DefaultNamedError{Err: namedErr.Error(), Name: namedErr.ErrorName()}
}
return &DefaultNamedError{Err: err.Error()}
}
type HostConfigError struct {
msg string
}
func (err *HostConfigError) Error() string { return err.msg }
func (err *HostConfigError) ErrorName() string { return "HostConfigError" }
type DockerClientConfigError struct {
msg string
}
func (err *DockerClientConfigError) Error() string { return err.msg }
func (err *DockerClientConfigError) ErrorName() string { return "DockerClientConfigError" }