generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 77
/
error.go
161 lines (131 loc) · 10.3 KB
/
error.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package utils
import (
"fmt"
"reflect"
"strconv"
"github.com/layer5io/meshkit/errors"
)
var (
ErrUnmarshalCode = "meshkit-11159"
ErrUnmarshalInvalidCode = "meshkit-11160"
ErrUnmarshalSyntaxCode = "meshkit-11161"
ErrUnmarshalTypeCode = "meshkit-11162"
ErrUnmarshalUnsupportedTypeCode = "meshkit-11163"
ErrUnmarshalUnsupportedValueCode = "meshkit-11164"
ErrMarshalCode = "meshkit-11165"
ErrGetBoolCode = "meshkit-11166"
ErrInvalidProtocolCode = "meshkit-11167"
ErrRemoteFileNotFoundCode = "meshkit-11168"
ErrReadingRemoteFileCode = "meshkit-11169"
ErrReadingLocalFileCode = "meshkit-11170"
ErrReadFileCode = "meshkit-11171"
ErrWriteFileCode = "meshkit-11172"
ErrGettingLatestReleaseTagCode = "meshkit-11173"
ErrInvalidProtocol = errors.New(ErrInvalidProtocolCode, errors.Alert, []string{"invalid protocol: only http, https and file are valid protocols"}, []string{}, []string{"Network protocol is incorrect"}, []string{"Make sure to specify the right network protocol"})
ErrMissingFieldCode = "meshkit-11174"
ErrExpectedTypeMismatchCode = "meshkit-11175"
ErrJsonToCueCode = "meshkit-11176"
ErrYamlToCueCode = "meshkit-11177"
ErrJsonSchemaToCueCode = "meshkit-11178"
ErrCueLookupCode = "meshkit-11179"
ErrTypeCastCode = "meshkit-11180"
ErrCreateFileCode = "meshkit-11181"
ErrCreateDirCode = "meshkit-11182"
// ErrDecodeYamlCode represents the error which is generated when yaml
// decode process fails
ErrDecodeYamlCode = "meshkit-11183"
ErrExtractTarXZCode = "meshkit-11184"
ErrExtractZipCode = "meshkit-11185"
ErrReadDirCode = "meshkit-11186"
)
func ErrCueLookup(err error) error {
return errors.New(ErrCueLookupCode, errors.Alert, []string{"Could not lookup the given path in the CUE value"}, []string{err.Error()}, []string{""}, []string{"make sure that the path is a valid cue expression and is correct", "make sure that there exists a field with the given path", "make sure that the given root value is correct"})
}
func ErrJsonSchemaToCue(err error) error {
return errors.New(ErrJsonSchemaToCueCode, errors.Alert, []string{"Could not convert given JsonSchema into a CUE Value"}, []string{err.Error()}, []string{"Invalid jsonschema"}, []string{"Make sure that the given value is a valid JSONSCHEMA"})
}
func ErrYamlToCue(err error) error {
return errors.New(ErrYamlToCueCode, errors.Alert, []string{"Could not convert given yaml object into a CUE Value"}, []string{err.Error()}, []string{"Invalid yaml"}, []string{"Make sure that the given value is a valid YAML"})
}
func ErrJsonToCue(err error) error {
return errors.New(ErrJsonToCueCode, errors.Alert, []string{"Could not convert given json object into a CUE Value"}, []string{err.Error()}, []string{"Invalid json object"}, []string{"Make sure that the given value is a valid JSON"})
}
func ErrExpectedTypeMismatch(err error, expectedType string) error {
return errors.New(ErrExpectedTypeMismatchCode, errors.Alert, []string{"Expected the type to be: ", expectedType}, []string{err.Error()}, []string{"Invalid manifest"}, []string{"Make sure that the value provided in the manifest has the needed type."})
}
func ErrMissingField(err error, missingFieldName string) error {
return errors.New(ErrMissingFieldCode, errors.Alert, []string{"Missing field or property with name: ", missingFieldName}, []string{err.Error()}, []string{"Invalid manifest"}, []string{"Make sure that the concerned data type has all the required fields/values."})
}
func ErrUnmarshal(err error) error {
return errors.New(ErrUnmarshalCode, errors.Alert, []string{"Unmarshal unknown error: "}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
}
func ErrUnmarshalInvalid(err error, typ reflect.Type) error {
return errors.New(ErrUnmarshalInvalidCode, errors.Alert, []string{"Unmarshal invalid error for type: ", typ.String()}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
}
func ErrUnmarshalSyntax(err error, offset int64) error {
return errors.New(ErrUnmarshalSyntaxCode, errors.Alert, []string{"Unmarshal syntax error at offest: ", strconv.Itoa(int(offset))}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
}
func ErrUnmarshalType(err error, value string) error {
return errors.New(ErrUnmarshalTypeCode, errors.Alert, []string{"Unmarshal type error at key: %s. Error: %s", value}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
}
func ErrUnmarshalUnsupportedType(err error, typ reflect.Type) error {
return errors.New(ErrUnmarshalUnsupportedTypeCode, errors.Alert, []string{"Unmarshal unsupported type error at key: ", typ.String()}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
}
func ErrUnmarshalUnsupportedValue(err error, value reflect.Value) error {
return errors.New(ErrUnmarshalUnsupportedValueCode, errors.Alert, []string{"Unmarshal unsupported value error at key: ", value.String()}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
}
func ErrMarshal(err error) error {
return errors.New(ErrMarshalCode, errors.Alert, []string{"Marshal error, Description: %s"}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
}
func ErrGetBool(key string, err error) error {
return errors.New(ErrGetBoolCode, errors.Alert, []string{"Error while getting Boolean value for key: %s, error: %s", key}, []string{err.Error()}, []string{"Not a valid boolean"}, []string{"Make sure it is a boolean"})
}
func ErrRemoteFileNotFound(url string) error {
return errors.New(ErrRemoteFileNotFoundCode, errors.Alert, []string{"remote file not found at", url}, []string{}, []string{"File doesnt exist in the location", "File name is incorrect"}, []string{"Make sure to input the right file name and location"})
}
func ErrReadingRemoteFile(err error) error {
return errors.New(ErrReadingRemoteFileCode, errors.Alert, []string{"error reading remote file"}, []string{err.Error()}, []string{"File doesnt exist in the location", "File name is incorrect"}, []string{"Make sure to input the right file name and location"})
}
func ErrReadingLocalFile(err error) error {
return errors.New(ErrReadingLocalFileCode, errors.Alert, []string{"error reading local file"}, []string{err.Error()}, []string{"File does not exist in the location (~/.kube/config)", "File is absent. Filename is not 'config'.", "Insufficient permissions to read file"}, []string{"Verify that the available kubeconfig is accessible by Meshery Server - verify sufficient file permissions (only needs read permission)."})
}
func ErrReadFile(err error, filepath string) error {
return errors.New(ErrReadFileCode, errors.Alert, []string{"error reading file"}, []string{err.Error()}, []string{fmt.Sprintf("File does not exist in the location %s", filepath), "Insufficient permissions"}, []string{"Verify that file exist at the provided location", "Verify sufficient file permissions."})
}
func ErrWriteFile(err error, filepath string) error {
return errors.New(ErrWriteFileCode, errors.Alert, []string{"error writing file"}, []string{err.Error()}, []string{fmt.Sprintf("File does not exist in the location %s", filepath), "Insufficient write permissions"}, []string{"Verify that file exist at the provided location", "Verify sufficient file permissions."})
}
func ErrCreateFile(err error, filepath string) error {
return errors.New(ErrCreateFileCode, errors.Alert, []string{fmt.Sprintf("error creating file at %s", filepath)}, []string{err.Error()}, []string{"invalid path provided", "insufficient permissions"}, []string{"provide a valid path", "retry by using an absolute path", "check for sufficient permissions for the user"})
}
func ErrCreateDir(err error, filepath string) error {
return errors.New(ErrCreateDirCode, errors.Alert, []string{fmt.Sprintf("error creating directory at %s", filepath)}, []string{err.Error()}, []string{"invalid path provided", "insufficient permissions"}, []string{"provide a valid path", "retry by using an absolute path", "check for sufficient permissions for the user"})
}
func ErrGettingLatestReleaseTag(err error) error {
return errors.New(
ErrGettingLatestReleaseTagCode,
errors.Alert,
[]string{"Could not fetch latest stable release from github"},
[]string{err.Error()},
[]string{"Failed to make GET request to github", "Invalid response received on github.com/<org>/<repo>/releases/stable"},
[]string{"Make sure Github is reachable", "Make sure a valid response is available on github.com/<org>/<repo>/releases/stable"},
)
}
func ErrTypeCast(err error) error {
return errors.New(ErrTypeCastCode, errors.Alert, []string{"invaid type assertion requested"}, []string{err.Error()}, []string{"The interface type is not compatible with the request type cast"}, []string{"use correct data type for type casting"})
}
// ErrDecodeYaml is the error when the yaml unmarshal fails
func ErrDecodeYaml(err error) error {
return errors.New(ErrDecodeYamlCode, errors.Alert, []string{"Error occurred while decoding YAML"}, []string{err.Error()}, []string{}, []string{})
}
// ErrExtractTarXVZ is the error for unzipping the targz file
func ErrExtractTarXZ(err error, path string) error {
return errors.New(ErrExtractTarXZCode, errors.Alert, []string{fmt.Sprintf("Error while extracting file at %s", path)}, []string{err.Error()}, []string{"The gzip might be corrupt"}, []string{})
}
// ErrExtractZip is the error for unzipping the zip file
func ErrExtractZip(err error, path string) error {
return errors.New(ErrExtractZipCode, errors.Alert, []string{fmt.Sprintf("Error while extracting file at %s", path)}, []string{err.Error()}, []string{"The zip might be corrupt"}, []string{})
}
func ErrReadDir(err error, dirPath string) error {
return errors.New(ErrReadDirCode, errors.Alert, []string{"error reading directory"}, []string{err.Error()}, []string{fmt.Sprintf("Directory does not exist at the location %s", dirPath), "Insufficient permissions"}, []string{"Verify that directory exist at the provided location", "Verify sufficient directory read permission."})
}