|
| 1 | +/* |
| 2 | + * Copyright (c) 2024. Devtron Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package errors |
| 18 | + |
| 19 | +import ( |
| 20 | + "google.golang.org/grpc/codes" |
| 21 | +) |
| 22 | + |
| 23 | +// list of error strings from Helm. These are part of the errors we check for presence in Helm's error messages. |
| 24 | +const ( |
| 25 | + ClusterUnreachableErrorMsg = "cluster unreachable" |
| 26 | + CrdPreconditionErrorMsg = "ensure crds are installed first" |
| 27 | + ArrayStringMismatchErrorMsg = "got array expected string" |
| 28 | + NotFoundErrorMsg = "not found" //this is a generic type constant, an error could be namespace "ns1" not found or service "ser1" not found. |
| 29 | + InvalidValueErrorMsg = "invalid value" |
| 30 | + OperationInProgressErrorMsg = "another operation (install/upgrade/rollback) is in progress" |
| 31 | + ForbiddenErrorMsg = "forbidden" |
| 32 | +) |
| 33 | + |
| 34 | +// list of internal errors, these errors are easy for the users to understand |
| 35 | +const ( |
| 36 | + InternalClusterUnreachableErrorMsg = "cluster unreachable" |
| 37 | + InternalOperationInProgressErrorMsg = "another operation (install/upgrade/rollback) is in progress" |
| 38 | +) |
| 39 | + |
| 40 | +type errorGrpcCodeTuple struct { |
| 41 | + errorMsg string |
| 42 | + grpcCode codes.Code |
| 43 | +} |
| 44 | + |
| 45 | +var helmErrorInternalErrorMap = map[string]errorGrpcCodeTuple{ |
| 46 | + ClusterUnreachableErrorMsg: {errorMsg: InternalClusterUnreachableErrorMsg, grpcCode: codes.DeadlineExceeded}, |
| 47 | + OperationInProgressErrorMsg: {errorMsg: InternalOperationInProgressErrorMsg, grpcCode: codes.FailedPrecondition}, |
| 48 | +} |
| 49 | + |
| 50 | +var DynamicErrorMapping = map[string]codes.Code{ |
| 51 | + NotFoundErrorMsg: codes.NotFound, |
| 52 | + ForbiddenErrorMsg: codes.PermissionDenied, |
| 53 | + InvalidValueErrorMsg: codes.InvalidArgument, |
| 54 | + ArrayStringMismatchErrorMsg: codes.InvalidArgument, |
| 55 | + CrdPreconditionErrorMsg: codes.FailedPrecondition, |
| 56 | +} |
0 commit comments