rlubke
rlubke

Reputation: 985

Invalid conversion from throwing function of type '(_) throws -> ()' to non-throwing function type '(CallResult) -> Void'

Have the following block of code:

do {
  try call.receiveMessage { callResult in
    if let msg = try callResult.resultData {
      let result = try decoder.decode(valueType, from: msg)
    }
    // other stuff
} catch let error {
  if let callback = self.onError {
    callback(error)
  }
}

this fails to compile due to an error at try call.receieveMessage:

Invalid conversion from throwing function of type '(_) throws -> ()' to non-throwing function type '(CallResult) -> Void'

The function I'm calling did indeed have a signature change:

from: public func receiveMessage(completion: @escaping (Data?) throws -> Void) throws { to: public func receiveMessage(completion: @escaping (CallResult) -> Void) throws {

What I'm having trouble getting my head around is the fact that other calls of this same method aren't having an issue, so I'm haven't quite nailed down what makes this particular block special.

Any advice would be appreciated.

Upvotes: 0

Views: 250

Answers (1)

rlubke
rlubke

Reputation: 985

Should have sat on it a bit longer. The resolution is to wrap the lambda with a do/catch.

Upvotes: 0

Related Questions