This repository has been archived by the owner on Nov 4, 2020. It is now read-only.
forked from aws/amazon-ecs-agent
/
errors.go
80 lines (64 loc) · 2.29 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
// Copyright 2014-2015 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"
)
const INSTANCE_TYPE_CHANGED_ERROR_MESSAGE = "Container instance type changes are not supported."
func IsInstanceTypeChangedError(err awserr.Error) bool {
return strings.Contains(err.Message(), INSTANCE_TYPE_CHANGED_ERROR_MESSAGE)
}
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
}
// NamedError is a wrapper type for 'error' which adds an optional name and provides a symetric 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" }