github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/errors.go (about) 1 package hedera 2 3 /*- 4 * 5 * Hedera Go SDK 6 * 7 * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 */ 22 23 import ( 24 "errors" 25 "fmt" 26 27 // "reflect" 28 29 "google.golang.org/grpc/codes" 30 ) 31 32 type ErrMaxChunksExceeded struct { 33 Chunks uint64 34 MaxChunks uint64 35 } 36 37 var errTransactionIsFrozen = errors.New("transaction is immutable; it has at least one signature or has been explicitly frozen") 38 var errNoClientOrTransactionID = errors.New("`client` must have an `_Operator` or `transactionId` must be set") 39 var errNoClientOrTransactionIDOrNodeId = errors.New("`client` must be provided or both `nodeId` and `transactionId` must be set") // nolint 40 var errClientOperatorSigning = errors.New("`client` must have an `_Operator` to sign with the _Operator") 41 var errNoClientProvided = errors.New("`client` must be provided and have an _Operator") 42 var errTransactionIsNotFrozen = errors.New("transaction is not frozen") 43 var errFailedToDeserializeBytes = errors.New("failed to deserialize bytes") 44 var errNoTransactionInBytes = errors.New("no transaction was found in bytes") 45 var errTransactionRequiresSingleNodeAccountID = errors.New("`PrivateKey.SignTransaction()` requires `Transaction` to have a single _Node `AccountID` set") 46 var errNoTransactions = errors.New("no transactions to execute") 47 var errByteArrayNull = errors.New("byte array can't be null") 48 var errParameterNull = errors.New("the parameter can't be null") 49 var errNetworkNameMissing = errors.New("can't derive checksum for ID without knowing which _Network the ID is for") 50 var errChecksumMissing = errors.New("no checksum provided") 51 var errLockedSlice = errors.New("slice is locked") 52 var errNodeIsUnhealthy = errors.New("node is unhealthy") 53 54 type ErrInvalidNodeAccountIDSet struct { 55 NodeAccountID AccountID 56 } 57 58 func (err ErrInvalidNodeAccountIDSet) Error() string { 59 return fmt.Sprintf("Invalid node AccountID was set for transaction: %v", err.NodeAccountID.String()) 60 } 61 62 func (err ErrMaxChunksExceeded) Error() string { 63 return fmt.Sprintf("Message requires %d chunks, but max chunks is %d", err.Chunks, err.MaxChunks) 64 } 65 66 // ErrMaxQueryPaymentExceeded is returned during query execution if the total cost of the query + estimated fees exceeds 67 // the max query payment threshold set on the client or QueryBuilder. 68 type ErrMaxQueryPaymentExceeded struct { 69 // The cost of the query that was attempted as returned by QueryBuilder.GetCost 70 QueryCost Hbar 71 // The limit for a single automatic query payment, set by 72 // Client.SetMaxQueryPayment(int64) or QueryBuilder.SetMaxQueryPayment(uint64). 73 MaxQueryPayment Hbar 74 // Name of the query transaction class used for output 75 query string 76 } 77 78 // Error() implements the Error interface 79 func (e ErrMaxQueryPaymentExceeded) Error() string { 80 return fmt.Sprintf("cost of %s (%s) without explicit payment is greater than the max query payment of %s", 81 e.query, 82 e.QueryCost.String(), 83 e.MaxQueryPayment.String()) 84 } 85 86 // ErrBadKey is returned if a key is provided in an invalid format or structure 87 type ErrBadKey struct { 88 message string 89 } 90 91 func _NewErrBadKeyf(format string, a ...interface{}) ErrBadKey { 92 return ErrBadKey{fmt.Sprintf(format, a...)} 93 } 94 95 // Error() implements the Error interface 96 func (e ErrBadKey) Error() string { 97 return e.message 98 } 99 100 // ErrHederaNetwork is returned in cases where the Hedera _Network cannot be reached or a _Network-side error occurs. 101 type ErrHederaNetwork struct { 102 error error 103 // GRPC Status Code 104 StatusCode *codes.Code 105 } 106 107 // Error() implements the Error interface 108 func (e ErrHederaNetwork) Error() string { 109 return fmt.Sprintf("transport error occurred while accessing the Hedera _Network: %s", e.error) 110 } 111 112 // ErrHederaPreCheckStatus is returned by Transaction.Execute and QueryBuilder.Execute if an exceptional status is 113 // returned during _Network side validation of the sent transaction. 114 type ErrHederaPreCheckStatus struct { 115 TxID TransactionID 116 Status Status 117 } 118 119 // Error() implements the Error interface 120 func (e ErrHederaPreCheckStatus) Error() string { 121 if e.TxID.AccountID == nil { 122 return fmt.Sprintf("exceptional precheck status %s", e.Status.String()) 123 } 124 if e.TxID.AccountID._IsZero() { 125 return fmt.Sprintf("exceptional precheck status %s", e.Status.String()) 126 } 127 return fmt.Sprintf("exceptional precheck status %s received for transaction %v", e.Status.String(), e.TxID) 128 } 129 130 // ErrHederaReceiptStatus is returned by TransactionID.GetReceipt if the status of the receipt is exceptional. 131 type ErrHederaReceiptStatus struct { 132 TxID TransactionID 133 Status Status 134 Receipt TransactionReceipt 135 } 136 137 func _NewErrHederaReceiptStatus(id TransactionID, status Status) ErrHederaReceiptStatus { 138 return ErrHederaReceiptStatus{TxID: id, Status: status} 139 } 140 141 // Error() implements the Error interface 142 func (e ErrHederaReceiptStatus) Error() string { 143 return fmt.Sprintf("exceptional receipt status: %s", e.Status.String()) 144 } 145 146 // ErrHederaRecordStatus is returned by TransactionID.GetRecord if the status of the record is exceptional. 147 type ErrHederaRecordStatus struct { 148 TxID TransactionID 149 Status Status 150 } 151 152 // Error() implements the Error interface 153 func (e ErrHederaRecordStatus) Error() string { 154 return fmt.Sprintf("exceptional precheck status %s", e.Status.String()) 155 } 156 157 // ErrLocalValidation is returned by TransactionBuilder.Build(*Client) and QueryBuilder.Execute(*Client) 158 // if the constructed transaction or query fails local sanity checks. 159 type ErrLocalValidation struct { 160 message string 161 } 162 163 // Error() implements the Error interface 164 func (e ErrLocalValidation) Error() string { 165 return e.message 166 }