Skip to content

Failure on returnResultAsyncIfNeeded without optional completion handler causes assertion failure #2004

@richardtop

Description

@richardtop

Bug report

Link to the source:

assertionFailure("Encountered failure result, but no completion handler was defined to handle it: \(error)")

A completion handler is defined as optional: action: ((Result<T, Error>) -> Void)?,, yet if not included, causes the program to crash with assertionFailure in case of a failure of the Result.

Based on the API, the lack of the completionHandler should not affect program execution in any way (hence, it's optional), and that's why I believe, this behavior is incompatible with the API declaration.

I suggest completely removing the assertionFailure and replacing it with debug logging message.

Versions

Please fill in the versions you're currently using:

  • apollo-ios SDK version: 0.49.1
  • Xcode version: 13.1
  • Swift version: 5.5
  • Package manager: Any

Steps to reproduce

Try calling static func returnResultAsyncIfNeeded<T>(on callbackQueue: DispatchQueue?, action: ((Result<T, Error>) -> Void)?, result: Result<T, Error>) { with the result that returns failure, on a debug build.
File: https://github.com/apollographql/apollo-ios/blob/main/Sources/Apollo/DispatchQueue%2BOptional.swift

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugGenerally incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions