<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Combine",
  "identifier" : "/documentation/Combine/Publisher/setFailureType(to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Combine"
    ],
    "preciseIdentifier" : "s:7Combine9PublisherPAAs5NeverO7FailureRtzrlE03setD4Type2toAA10PublishersO03SetdF0Vy_xqd__Gqd__m_ts5ErrorRd__lF"
  },
  "title" : "setFailureType(to:)"
}
-->

# setFailureType(to:)

Changes the failure type declared by the upstream publisher.

```
func setFailureType<E>(to failureType: E.Type) -> Publishers.SetFailureType<Self, E> where E : Error
```

## Parameters

`failureType`

The `Failure` type presented by this publisher.

## Return Value

A publisher that appears to send the specified failure type.

## Discussion

Use [`setFailureType(to:)`](/documentation/Combine/Publisher/setFailureType(to:)) when you need set the error type of a publisher that cannot fail.

Conversely, if the upstream can fail, you would use [`mapError(_:)`](/documentation/Combine/Publisher/mapError(_:)) to provide instructions on converting the error types to needed by the downstream publisher’s inputs.

The following example has two publishers with mismatched error types: `pub1`’s error type is <doc://com.apple.documentation/documentation/Swift/Never>, and `pub2`’s error type is <doc://com.apple.documentation/documentation/Swift/Error>. Because of the mismatch, the [`combineLatest(_:)`](/documentation/Combine/Publisher/combineLatest(_:)) operator requires that `pub1` use [`setFailureType(to:)`](/documentation/Combine/Publisher/setFailureType(to:)) to make it appear that `pub1` can produce the <doc://com.apple.documentation/documentation/Swift/Error> type, like `pub2` can.

```
let pub1 = [0, 1, 2, 3, 4, 5].publisher
let pub2 = CurrentValueSubject<Int, Error>(0)
let cancellable = pub1
    .setFailureType(to: Error.self)
    .combineLatest(pub2)
    .sink(
        receiveCompletion: { print ("completed: \($0)") },
        receiveValue: { print ("value: \($0)")}
     )

// Prints: "value: (5, 0)".
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)