What are valid combinations of completion handler parameter values for `URLSession.uploadTask(with:from:completionHandler:)`?

The parameters of the completion handler are (data: Optional<Data>, urlResponse: Optional<Data>, error: Optional<Error>). Here is an exhaustive switch statement of the parameter combinations:

switch (data, ulrResponse, error) {
      case (.some, .some, .some):
      case (.some, .some, .none):
      case (.some, .none, .some):
      case (.some, .none, .none):
      case (.none, .some, .some):
      case (.none, .none, .some):
      case (.none, .some, .none):
      case (.none, .none, .none):
} 

Which combinations of values may be provided and which will not?

For example, I think it's fair to say that both (.some, .none, .some) and (.some, .none, .none) are invalid because a response would have to be provided in order to receive data to pass to the closure, and the documentation states:

If a response from the server is received, regardless of whether the request completes successfully or fails, the response parameter contains that information.

Replies

Asking here in the forum is proof that the documentation isn’t exactly complete. But we may be able to infer clues from the equivalent newer async method upload(for:from:delegate:). That method either returns a (Data, URLResponse) tuple or throws an error, so we know you’ll never get data or a response in the case of an error. And note the return tuple’s URLResponse is non-optional, so it will always be present if no error. The tuple’s Data is also non-optional but could be empty, so we can’t say for sure if that’s the case in the old version of the method. Probably best to handle both a nil data and an empty data the same way.