ipfs-shipyard/gomobile-ipfs

When I use files/rm or cp, it report Error "sending request failed"

westice007 opened this issue · 7 comments

Asking a question, not reporting a bug

  • This question is not about a bug

Is there an existing issue for this?

  • I have searched the existing issues

Question

do {
let res1 = try self.ipfs?.newRequest("files/rm")
.with(argument: mfsPath)
.send()
print("exeRmCmd files/rm res1: ", res1)
return res1
}catch let error {
print("Error: exeRmCmd Rm: (error) mfsPath:(mfsPath)")
}

the msfPath is Exist , can be readed use files/stat
but files/rm cp catch Error:
Error Domain=IPFS.RequestBuilder Code=6 "sending request failed" UserInfo={NSLocalizedDescription=sending request failed, NSLocalizedFailureReason=The operation couldn’t be completed. (Foundation._GenericObjCError error 0.)}

Context

How to solve this problem?

Hello @westice007 . I am able to reproduce your error with files/cp . For me, I see this error. But if I use files/ls, then it shows that the file was added by files/cp . What does files/ls show on your system?

@jefft0 Instead of using files/ls, I use files/stat to check file, files/ls should be used to check folders

@westice007 , thanks for the clarification. I mean to ask, even if files/cp shows an error, is the file created on your phone?

When I use files/cp, I get an error, but the file copy is successful, and then I can check the result with files/stat
this is my code:

func exeCpCmd(srcPath: String, mfsPath: String) -> String? {
    do {
        let res = try self.ipfs?.newRequest("files/cp")
            .with(argument: srcPath).with(argument: mfsPath)
            .send()
    } catch let error {
        print("this is bug: exeCpCmd cp: \(error) hashId:\(srcPath) mfsPath:\(mfsPath)")
    }
    
    var changedHash: String?

    do {
        var fileInfo : [String: Any]? = [String: Any]()
        fileInfo = try self.ipfs!.newRequest("files/stat")
        .with(argument: mfsPath)
        .sendToDict()
        changedHash = fileInfo?["Hash"] as? String
    } catch let error {
        //print("exeCpCmd cp: \(error) hashId:\(srcPath) mfsPath:\(mfsPath)")
        
    }
    return changedHash
}

Thank you for confirming. This is the same behavior for me. We have found the cause of the error. Because files/cp returns an empty response, the return value should be nil. This works in Java (Android), but there is a behavior in the Swift/Go binding code which prevents returning a nil result. We are working on resolving it.

Hello @westice007 . We merged pull request #135 into master which fixes this crash in the Swift code. Can you please check if it fixes your problem? Thanks.

As mentioned. We merged a fix. Closing this issue as resolved. If you still see the error, then please open another issue. Thank you.