Skip to content

Commit

Permalink
Merge pull request #1 from GabCas/feature/Web3ErrorDescription
Browse files Browse the repository at this point in the history
adding description string to Web3Error
  • Loading branch information
shamatar authored Aug 25, 2018
2 parents c049c9e + be992c9 commit 71f54d0
Show file tree
Hide file tree
Showing 24 changed files with 139 additions and 113 deletions.
2 changes: 1 addition & 1 deletion web3swift/ABIv2/Classes/ABIv2TypeParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public struct ABIv2TypeParser {

public static func parseTypeString(_ string:String) throws -> ABIv2.Element.ParameterType {
let (type, tail) = recursiveParseType(string)
guard let t = type, tail == nil else {throw Web3Error.inputError("Failed to parse ABI element " + string)}
guard let t = type, tail == nil else {throw Web3Error.inputError(desc: "Failed to parse ABI element " + string)}
return t
}

Expand Down
8 changes: 4 additions & 4 deletions web3swift/HookedFunctions/Classes/Web3+Wallet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ extension web3.Web3Wallet {
return Result(true)
} catch {
if error is AbstractKeystoreError {
return Result.failure(Web3Error.keystoreError(error as! AbstractKeystoreError))
return Result.failure(Web3Error.keystoreError(err: error as! AbstractKeystoreError))
}
return Result.failure(Web3Error.generalError(error))
return Result.failure(Web3Error.generalError(err: error))
}
}

Expand All @@ -71,9 +71,9 @@ extension web3.Web3Wallet {
}
catch{
if error is AbstractKeystoreError {
return Result.failure(Web3Error.keystoreError(error as! AbstractKeystoreError))
return Result.failure(Web3Error.keystoreError(err: error as! AbstractKeystoreError))
}
return Result.failure(Web3Error.generalError(error))
return Result.failure(Web3Error.generalError(err: error))
}
}

Expand Down
4 changes: 2 additions & 2 deletions web3swift/ObjectiveCbridge/Classes/Web3+Eth+ObjC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public final class _ObjCweb3Eth: NSObject {

public func getBalance(address: _ObjCEthereumAddress, onBlock: NSString = "latest", error: NSErrorPointer) -> _ObjCBigUInt? {
guard let addr = address.address else {
error?.pointee = Web3Error.inputError("Address is empty") as NSError
error?.pointee = Web3Error.inputError(desc: "Address is empty") as NSError
return nil
}
guard let result = self.web3?.eth.getBalance(address: addr, onBlock: onBlock as String) else {
error?.pointee = Web3Error.processingError("Web3 object was not properly initialized") as NSError
error?.pointee = Web3Error.processingError(desc: "Web3 object was not properly initialized") as NSError
return nil
}
switch result {
Expand Down
8 changes: 4 additions & 4 deletions web3swift/Promises/Classes/Promise+Batching.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public class JSONRPCrequestDispatcher {
var triggered : Bool = false
func add(_ request: JSONRPCrequest, maxWaitTime: TimeInterval) throws -> Promise<JSONRPCresponse> {
if self.triggered {
throw Web3Error.nodeError("Batch is already in flight")
throw Web3Error.nodeError(desc: "Batch is already in flight")
}
let requestID = request.id
let promiseToReturn = Promise<JSONRPCresponse>.pending()
self.lockQueue.async {
if self.promisesDict[requestID] != nil {
promiseToReturn.resolver.reject(Web3Error.processingError("Request ID collision"))
promiseToReturn.resolver.reject(Web3Error.processingError(desc: "Request ID collision"))
}
self.promisesDict[requestID] = promiseToReturn
self.requests.append(request)
Expand All @@ -71,7 +71,7 @@ public class JSONRPCrequestDispatcher {
for response in batch.responses {
if self.promisesDict[UInt64(response.id)] == nil {
for k in self.promisesDict.keys {
self.promisesDict[k]?.resolver.reject(Web3Error.nodeError("Unknown request id"))
self.promisesDict[k]?.resolver.reject(Web3Error.nodeError(desc: "Unknown request id"))
}
return
}
Expand All @@ -98,7 +98,7 @@ public class JSONRPCrequestDispatcher {

func getBatch() throws -> Batch {
guard case .Batch(let batchLength) = self.policy else {
throw Web3Error.inputError("Trying to batch a request when policy is not to batch")
throw Web3Error.inputError(desc: "Trying to batch a request when policy is not to batch")
}
let currentBatch = self.batches.last!
if currentBatch.requests.count % batchLength == 0 || currentBatch.triggered {
Expand Down
8 changes: 4 additions & 4 deletions web3swift/Promises/Classes/Promise+HttpProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension Web3HttpProvider {
return
}
guard data != nil else {
rp.resolver.reject(Web3Error.nodeError("Node response is empty"))
rp.resolver.reject(Web3Error.nodeError(desc: "Node response is empty"))
return
}
rp.resolver.fulfill(data!)
Expand All @@ -48,7 +48,7 @@ extension Web3HttpProvider {
}.map(on: queue){ (data: Data) throws -> JSONRPCresponse in
let parsedResponse = try JSONDecoder().decode(JSONRPCresponse.self, from: data)
if parsedResponse.error != nil {
throw Web3Error.nodeError("Received an error message from node\n" + String(describing: parsedResponse.error!))
throw Web3Error.nodeError(desc: "Received an error message from node\n" + String(describing: parsedResponse.error!))
}
return parsedResponse
}
Expand Down Expand Up @@ -76,7 +76,7 @@ extension Web3HttpProvider {
return
}
guard data != nil, data!.count != 0 else {
rp.resolver.reject(Web3Error.nodeError("Node response is empty"))
rp.resolver.reject(Web3Error.nodeError(desc: "Node response is empty"))
return
}
rp.resolver.fulfill(data!)
Expand All @@ -98,7 +98,7 @@ extension Web3HttpProvider {

public func sendAsync(_ request: JSONRPCrequest, queue: DispatchQueue = .main) -> Promise<JSONRPCresponse> {
if request.method == nil {
return Promise(error: Web3Error.nodeError("RPC method is nill"))
return Promise(error: Web3Error.nodeError(desc: "RPC method is nill"))
}

return Web3HttpProvider.post(request, providerURL: self.url, queue: queue, session: self.session)
Expand Down
6 changes: 3 additions & 3 deletions web3swift/Promises/Classes/Promise+Web3+Eth+Call.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ extension web3.Eth {
let queue = web3.requestDispatcher.queue
do {
guard let request = EthereumTransaction.createRequest(method: .call, transaction: transaction, onBlock: onBlock, options: options) else {
throw Web3Error.processingError("Transaction is invalid")
throw Web3Error.processingError(desc: "Transaction is invalid")
}
let rp = web3.dispatch(request)
return rp.map(on: queue ) { response in
guard let value: Data = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(response.error!.message)
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError("Invalid value from Ethereum node")
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value
}
Expand Down
6 changes: 3 additions & 3 deletions web3swift/Promises/Classes/Promise+Web3+Eth+EstimateGas.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ extension web3.Eth {
let queue = web3.requestDispatcher.queue
do {
guard let request = EthereumTransaction.createRequest(method: .estimateGas, transaction: transaction, onBlock: onBlock, options: options) else {
throw Web3Error.processingError("Transaction is invalid")
throw Web3Error.processingError(desc: "Transaction is invalid")
}
let rp = web3.dispatch(request)
return rp.map(on: queue ) { response in
guard let value: BigUInt = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(response.error!.message)
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError("Invalid value from Ethereum node")
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value
}
Expand Down
4 changes: 2 additions & 2 deletions web3swift/Promises/Classes/Promise+Web3+Eth+GetAccounts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ extension web3.Eth {
return rp.map(on: queue ) { response in
guard let value: [EthereumAddress] = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(response.error!.message)
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError("Invalid value from Ethereum node")
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value
}
Expand Down
4 changes: 2 additions & 2 deletions web3swift/Promises/Classes/Promise+Web3+Eth+GetBalance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ extension web3.Eth {
return rp.map(on: queue ) { response in
guard let value: BigUInt = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(response.error!.message)
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError("Invalid value from Ethereum node")
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ extension web3.Eth {
return rp.map(on: queue ) { response in
guard let value: Block = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(response.error!.message)
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError("Invalid value from Ethereum node")
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ extension web3.Eth {
return rp.map(on: queue ) { response in
guard let value: Block = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(response.error!.message)
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError("Invalid value from Ethereum node")
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ extension web3.Eth {
return rp.map(on: queue ) { response in
guard let value: BigUInt = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(response.error!.message)
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError("Invalid value from Ethereum node")
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value
}
Expand Down
4 changes: 2 additions & 2 deletions web3swift/Promises/Classes/Promise+Web3+Eth+GetGasPrice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ extension web3.Eth {
return rp.map(on: queue ) { response in
guard let value: BigUInt = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(response.error!.message)
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError("Invalid value from Ethereum node")
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ extension web3.Eth {
return rp.map(on: queue ) { response in
guard let value: BigUInt = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(response.error!.message)
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError("Invalid value from Ethereum node")
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ extension web3.Eth {
return rp.map(on: queue ) { response in
guard let value: TransactionDetails = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(response.error!.message)
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError("Invalid value from Ethereum node")
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ extension web3.Eth {
return rp.map(on: queue ) { response in
guard let value: TransactionReceipt = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(response.error!.message)
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError("Invalid value from Ethereum node")
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension web3.Eth {
func sendRawTransactionPromise(_ transaction: Data) -> Promise<TransactionSendingResult> {
guard let deserializedTX = EthereumTransaction.fromRaw(transaction) else {
let promise = Promise<TransactionSendingResult>.pending()
promise.resolver.reject(Web3Error.processingError("Serialized TX is invalid"))
promise.resolver.reject(Web3Error.processingError(desc: "Serialized TX is invalid"))
return promise.promise
}
return sendRawTransactionPromise(deserializedTX)
Expand All @@ -24,15 +24,15 @@ extension web3.Eth {
let queue = web3.requestDispatcher.queue
do {
guard let request = EthereumTransaction.createRawTransaction(transaction: transaction) else {
throw Web3Error.processingError("Transaction is invalid")
throw Web3Error.processingError(desc: "Transaction is invalid")
}
let rp = web3.dispatch(request)
return rp.map(on: queue ) { response in
guard let value: String = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(response.error!.message)
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError("Invalid value from Ethereum node")
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
let result = TransactionSendingResult(transaction: transaction, hash: value)
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ extension web3.Eth {
if self.web3.provider.attachedKeystoreManager == nil {
guard let request = EthereumTransaction.createRequest(method: JSONRPCmethod.sendTransaction, transaction: assembledTransaction, onBlock: nil, options: options) else
{
throw Web3Error.processingError("Failed to create a request to send transaction")
throw Web3Error.processingError(desc: "Failed to create a request to send transaction")
}
return self.web3.dispatch(request).map(on: queue) {response in
guard let value: String = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(response.error!.message)
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError("Invalid value from Ethereum node")
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
let result = TransactionSendingResult(transaction: assembledTransaction, hash: value)
return result
}
}
guard let from = options.from else {
throw Web3Error.inputError("No 'from' field provided")
throw Web3Error.inputError(desc: "No 'from' field provided")
}
do {
try Web3Signer.signTX(transaction: &assembledTransaction, keystore: self.web3.provider.attachedKeystoreManager!, account: from, password: password)
} catch {
throw Web3Error.inputError("Failed to locally sign a transaction")
throw Web3Error.inputError(desc: "Failed to locally sign a transaction")
}
return self.web3.eth.sendRawTransactionPromise(assembledTransaction)
} catch {
Expand Down
6 changes: 3 additions & 3 deletions web3swift/Promises/Classes/Promise+Web3+Personal+Sign.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ extension web3.Personal {
return self.web3.dispatch(request).map(on: queue) {response in
guard let value: Data = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(response.error!.message)
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError("Invalid value from Ethereum node")
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value
}
}
guard let signature = try Web3Signer.signPersonalMessage(message, keystore: self.web3.provider.attachedKeystoreManager!, account: from, password: password) else { throw Web3Error.inputError("Failed to locally sign a message") }
guard let signature = try Web3Signer.signPersonalMessage(message, keystore: self.web3.provider.attachedKeystoreManager!, account: from, password: password) else { throw Web3Error.inputError(desc: "Failed to locally sign a message") }
let returnPromise = Promise<Data>.pending()
queue.async {
returnPromise.resolver.fulfill(signature)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ extension web3.Personal {
return self.web3.dispatch(request).map(on: queue) {response in
guard let value: Bool = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(response.error!.message)
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError("Invalid value from Ethereum node")
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value
}
}
throw Web3Error.inputError("Can not unlock a local keystore")
throw Web3Error.inputError(desc: "Can not unlock a local keystore")
} catch {
let returnPromise = Promise<Bool>.pending()
queue.async {
Expand Down
Loading

0 comments on commit 71f54d0

Please sign in to comment.