PromiseKit: 3.0.0: Cannot call value of non-function type 'ErrorType?'

Installed PromiseKit 3.0.0 via Cocoapods. The following code generates a compile error (Xcode Version 7.2 (7C68)):

let (p2, _, _) = Promise<Void>.pendingPromise()
p2.error { error -> Void in
        NSLog("Error: %@", error)
}

This appears to be because Promise+Properties.swift defines public var error: ErrorType? and Promise.swift defines public func error(policy policy: ErrorPolicy = .AllErrorsExceptCancellation, _ body: (ErrorType) -> Void).

I’m not sure Swift allows you to have properties with the same names as functions. The Swift compiler is getting confused.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (11 by maintainers)

Most upvoted comments

It happens to me often when the code within the error block has compiler errors. For instance:

API.instance.cancelTripRequest(tripRequest).then { _ -> Void in
    self.onTripRequestCancelled(tripRequest)
}.error { error in // Cannot call value of non-function type 'ErrorType?'
    Kugel.publish(TripRequestCancelFailed, object: error.nsError)
}

But the actual error is within the error block: TripRequestCancelFailed is a static member of the current class, not a global variable. A good way to debug this is by moving your error code outside of the error block, and see what the compiler says.

Not sure it’s the cause of your issue, but I thought it was worth mentioning.

@orj @nathanhosselton

I get the same error and can’t figure out how to solve it. Any tips?

func promise1() -> Promise<Class1>
func promise2() -> Promise<Void>

func promise1and2() -> Promise<Void> {
    return promise1().then { class1object in
        return promise2()
    }.error { error in
        log.error(error)
    }
}

Thanks!