Skip to content

Commit cfd8ee9

Browse files
chore: updated error messages for EIP712Parser
1 parent 40a9a3d commit cfd8ee9

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Sources/web3swift/Utils/EIP/EIP712/EIP712Parser.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public class EIP712Parser {
9090

9191
static func toData(_ json: String) throws -> Data {
9292
guard let json = json.data(using: .utf8) else {
93-
throw Web3Error.inputError(desc: "Failed to parse EIP712 payload. Given string is not valid UTF8 string. \(json)")
93+
throw Web3Error.inputError(desc: "EIP712Parser. Failed to parse EIP712 payload. Given string is not valid UTF8 string. \(json)")
9494
}
9595
return json
9696
}
@@ -176,7 +176,7 @@ public struct EIP712TypedData {
176176

177177
public func encodeType(_ type: String) throws -> String {
178178
guard let typeData = types[type] else {
179-
throw Web3Error.processingError(desc: "EIP712. Attempting to encode type that doesn't exist in this payload. Given type: \(type). Available types: \(types.values).")
179+
throw Web3Error.processingError(desc: "EIP712Parser. Attempting to encode type that doesn't exist in this payload. Given type: \(type). Available types: \(types.values).")
180180
}
181181
return try encodeType(type, typeData)
182182
}
@@ -216,7 +216,7 @@ public struct EIP712TypedData {
216216
var encValues: [Any] = [try typeHash(type)]
217217

218218
guard let typeData = types[type] else {
219-
throw Web3Error.processingError(desc: "EIP712. Attempting to encode data for type that doesn't exist in this payload. Given type: \(type). Available types: \(types.values).")
219+
throw Web3Error.processingError(desc: "EIP712Parser. Attempting to encode data for type that doesn't exist in this payload. Given type: \(type). Available types: \(types.values).")
220220
}
221221

222222
func encodeField(_ field: EIP712TypeProperty,
@@ -225,19 +225,19 @@ public struct EIP712TypedData {
225225
var encValues: [Any] = []
226226
if field.type == "string" {
227227
guard let value = value as? String else {
228-
throw Web3Error.processingError(desc: "EIP712. Type metadata '\(field)' and actual value '\(String(describing: value))' type doesn't match. Cannot cast value to String.")
228+
throw Web3Error.processingError(desc: "EIP712Parser. Type metadata '\(field)' and actual value '\(String(describing: value))' type doesn't match. Cannot cast value to String.")
229229
}
230230
encTypes.append(.bytes(length: 32))
231231
encValues.append(value.sha3(.keccak256).addHexPrefix())
232232
} else if field.type == "bytes"{
233233
guard let value = value as? Data else {
234-
throw Web3Error.processingError(desc: "EIP712. Type metadata '\(field)' and actual value '\(String(describing: value))' type doesn't match. Cannot cast value to Data.")
234+
throw Web3Error.processingError(desc: "EIP712Parser. Type metadata '\(field)' and actual value '\(String(describing: value))' type doesn't match. Cannot cast value to Data.")
235235
}
236236
encTypes.append(.bytes(length: 32))
237237
encValues.append(value.sha3(.keccak256))
238238
} else if field.isArray {
239239
guard let values = value as? [AnyObject] else {
240-
throw Web3Error.processingError(desc: "EIP712. Custom type metadata '\(field)' and actual value '\(String(describing: value))' type doesn't match. Cannot cast value to [AnyObject].")
240+
throw Web3Error.processingError(desc: "EIP712Parser. Custom type metadata '\(field)' and actual value '\(String(describing: value))' type doesn't match. Cannot cast value to [AnyObject].")
241241
}
242242
encTypes.append(.bytes(length: 32))
243243
let subField = EIP712TypeProperty(name: field.name, type: field.coreType)
@@ -250,7 +250,7 @@ public struct EIP712TypedData {
250250
}
251251

252252
guard let encodedValue = ABIEncoder.encode(types: encodedSubTypes, values: encodedSubValues) else {
253-
throw Web3Error.processingError(desc: "EIP712. Failed to encode an array of custom type. Field: '\(field)'; value: '\(String(describing: value))'.")
253+
throw Web3Error.processingError(desc: "EIP712Parser. Failed to encode an array of custom type. Field: '\(field)'; value: '\(String(describing: value))'.")
254254
}
255255

256256
encValues.append(encodedValue.sha3(.keccak256))
@@ -276,7 +276,7 @@ public struct EIP712TypedData {
276276
}
277277

278278
guard let encodedData = ABIEncoder.encode(types: encTypes, values: encValues) else {
279-
throw Web3Error.processingError(desc: "EIP712. ABIEncoder.encode failed with the following types and values: \(encTypes); \(encValues)")
279+
throw Web3Error.processingError(desc: "EIP712Parser. ABIEncoder.encode failed with the following types and values: \(encTypes); \(encValues)")
280280
}
281281
return encodedData
282282
}

0 commit comments

Comments
 (0)