* Copyright (c) 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License 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 errmsg
import (
"meta_service/common/snerror"
)
const (
descriptionSeparator = ". "
FunctionNameExist = 4101
AliasNameAlreadyExists = 4102
TotalRoutingWeightNotOneHundred = 4103
InvalidUserParam = 4104
FunctionVersionDeletionForbidden = 4105
LayerVersionSizeOutOfLimit = 4106
TenantLayerSizeOutOfLimit = 4107
LayerVersionNumOutOfLimit = 4108
TriggerNumOutOfLimit = 4109
FunctionVersionOutOfLimit = 4110
AliasOutOfLimit = 4111
LayerIsUsed = 4112
LayerVersionNotFound = 4113
RepeatedPublishmentError = 4114
FunctionNotFound = 4115
FunctionVersionNotFound = 4116
AliasNameNotFound = 4117
TriggerNotFound = 4118
LayerNotFound = 4119
PoolNotFound = 4120
PageInfoError = 4123
TriggerPathRepeated = 4124
DuplicateCompatibleRuntimes = 4125
CompatibleRuntimeError = 4126
ZipFileCountError = 4127
ZipFilePathError = 4128
ZipFileUnzipSizeError = 4129
ZipFileSizeError = 4130
RevisionIDError = 4134
SaveFileError = 121016
UploadFileError = 121017
EmptyAliasAndVersion = 121018
ReadingPackageTimeout = 121019
BucketNotFound = 121026
ZipFileError = 121029
DownloadFileError = 121030
DeleteFileError = 121032
InvalidFunctionLayer = 121036
InvalidQueryURN = 121046
InvalidQualifier = 121047
ReadBodyError = 121048
AuthCheckError = 121049
InvalidJSONBody = 121052
InvalidParamErrorCode = 130600
TriggerIDNotFound = 121057
FunctionNameFormatErr = 121058
KVNotFound = 122001
EtcdError = 122002
TransactionFailed = 122003
UnmarshalFailed = 122004
MarshalFailed = 122005
VersionOrAliasEmpty = 122006
ResourceIDEmpty = 122007
NoTenantInfo = 122008
NoResourceInfo = 122009
)
var checkInputParamMsg = "check input parameters"
var errorMsg = map[int]string{
InvalidUserParam: userMessage("%s", checkInputParamMsg),
FunctionNameExist: userMessage("the function name already exists", "rename your function"),
RevisionIDError: "revisionID is not the same",
FunctionVersionNotFound: userMessage("function [%s] version [%s] is not found", checkInputParamMsg),
FunctionVersionDeletionForbidden: userMessage("this version is occupied by an alias", "remove the "+
"mapping first"),
FunctionNotFound: userMessage("function [%s] is not found", checkInputParamMsg),
LayerVersionSizeOutOfLimit: userMessage("the version size [%d] is larger than max config size [%d]",
"delete or resize"),
TenantLayerSizeOutOfLimit: userMessage("the tenant layer size [%d] is larger than the maximum config size [%d"+
"]", "consult the administrator"),
LayerVersionNumOutOfLimit: userMessage("the maximum layer version number is larger than the config num [%d]",
checkInputParamMsg),
LayerIsUsed: userMessage("layer version %d has been bound to the function",
"please unbind it before performing the operation"),
PageInfoError: userMessage("the page information is out of the query range", checkInputParamMsg),
LayerNotFound: userMessage("layer [%s] not found", checkInputParamMsg),
DuplicateCompatibleRuntimes: userMessage("duplicated compatibleRuntimes exists", checkInputParamMsg),
CompatibleRuntimeError: userMessage("compatible runtime is invalid", checkInputParamMsg),
TriggerPathRepeated: userMessage("trigger path is repeated", checkInputParamMsg),
TriggerNumOutOfLimit: userMessage("the number of triggers exceeds the upper limit [%d]",
"delete or resize the limit"),
TriggerNotFound: userMessage("trigger [%s] is not found", checkInputParamMsg),
TriggerIDNotFound: userMessage("trigger [%s] is not found", checkInputParamMsg),
AliasNameNotFound: userMessage("functionName [%s] and aliasName [%s] do not exist", checkInputParamMsg),
AliasOutOfLimit: userMessage("the number of existing function alias is greater than the set value [%d]",
"delete or resize the limit"),
InvalidJSONBody: "request body is not a valid JSON object",
TotalRoutingWeightNotOneHundred: userMessage("total routing weight is not 100",
"check the routing weight. the sum of the values is 100"),
}
var (
KeyNotFoundError = snerror.New(KVNotFound, "KV not exist in etcd")
EtcdInternalError = snerror.New(EtcdError, "etcd internal error")
EtcdTransactionFailedError = snerror.New(TransactionFailed, "etcd transaction failed")
UnmarshalError = snerror.New(UnmarshalFailed, "failed to unmarshal")
MarshalError = snerror.New(MarshalFailed, "failed to marshal")
VersionOrAliasError = snerror.New(VersionOrAliasEmpty, "version or alias name is empty")
ResourceIDError = snerror.New(ResourceIDEmpty, "resource ID is empty")
PageError = snerror.New(PageInfoError, "page size cannot be 0")
PoolNotFoundError = snerror.New(PoolNotFound, userMessage("pool does not exist or has been deleted",
checkInputParamMsg))
)
func ErrorMessage(code int) string {
return errorMsg[code]
}
func userMessage(msg string, suggestions string) string {
return msg + descriptionSeparator + suggestions
}
func New(code int, v ...interface{}) snerror.SNError {
return snerror.NewWithFmtMsg(code, ErrorMessage(code), v...)
}
func NewParamError(msg string, v ...interface{}) snerror.SNError {
return snerror.NewWithFmtMsg(InvalidUserParam, userMessage(msg, checkInputParamMsg), v...)
}