From cfb8d125a5767e60fe8a74f5cff57493424f15c8 Mon Sep 17 00:00:00 2001 From: Chase Fleming <1666730+chasefleming@users.noreply.github.com> Date: Mon, 15 Sep 2025 13:13:05 -0700 Subject: [PATCH 1/2] Create codes package --- internal/errors/codes.go | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 internal/errors/codes.go diff --git a/internal/errors/codes.go b/internal/errors/codes.go new file mode 100644 index 000000000..97dcf16b6 --- /dev/null +++ b/internal/errors/codes.go @@ -0,0 +1,44 @@ +/* + * Flow CLI + * + * Copyright Flow Foundation + * + * 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 errors + +import ( + "fmt" + "strings" +) + +// Flow error codes +const ( + StorageLimitExceeded = 1103 +) + +// HasErrorCode checks if an error contains a specific Flow error code +func HasErrorCode(err error, code int) bool { + if err == nil { + return false + } + + errorCodePattern := fmt.Sprintf("[Error Code: %d]", code) + return strings.Contains(err.Error(), errorCodePattern) +} + +// IsStorageLimitError checks if an error is a storage limit exceeded error +func IsStorageLimitError(err error) bool { + return HasErrorCode(err, StorageLimitExceeded) +} \ No newline at end of file From d3a8ce21a7857050b185a45113953f7c38845cf2 Mon Sep 17 00:00:00 2001 From: Chase Fleming <1666730+chasefleming@users.noreply.github.com> Date: Mon, 15 Sep 2025 13:17:37 -0700 Subject: [PATCH 2/2] Switch to reusable method --- internal/errors/codes.go | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/internal/errors/codes.go b/internal/errors/codes.go index 97dcf16b6..e16ca3121 100644 --- a/internal/errors/codes.go +++ b/internal/errors/codes.go @@ -23,11 +23,18 @@ import ( "strings" ) -// Flow error codes +// FlowErrorType represents different types of Flow errors +type FlowErrorType string + const ( - StorageLimitExceeded = 1103 + StorageLimitExceeded FlowErrorType = "storage_limit" ) +// Flow error codes mapped to their types +var errorCodeMap = map[int]FlowErrorType{ + 1103: StorageLimitExceeded, +} + // HasErrorCode checks if an error contains a specific Flow error code func HasErrorCode(err error, code int) bool { if err == nil { @@ -38,7 +45,16 @@ func HasErrorCode(err error, code int) bool { return strings.Contains(err.Error(), errorCodePattern) } -// IsStorageLimitError checks if an error is a storage limit exceeded error -func IsStorageLimitError(err error) bool { - return HasErrorCode(err, StorageLimitExceeded) -} \ No newline at end of file +// IsErrorType checks if an error is of a specific Flow error type +func IsErrorType(err error, errorType FlowErrorType) bool { + if err == nil { + return false + } + + for code, errType := range errorCodeMap { + if errType == errorType && HasErrorCode(err, code) { + return true + } + } + return false +}