From cba369e2479714f75792d63a54eef6cda4fc3ebb Mon Sep 17 00:00:00 2001 From: Vatsal Manot Date: Sat, 11 Jan 2025 20:40:49 -0800 Subject: [PATCH] Update package --- .../Foundation/TaskSuccessPublisher.swift | 14 +++++++++++++- .../Status/ObservableTaskFailure.swift | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Sources/Merge/Intramodular/Observable Tasks/Foundation/TaskSuccessPublisher.swift b/Sources/Merge/Intramodular/Observable Tasks/Foundation/TaskSuccessPublisher.swift index 6b526bd..c9c5b78 100644 --- a/Sources/Merge/Intramodular/Observable Tasks/Foundation/TaskSuccessPublisher.swift +++ b/Sources/Merge/Intramodular/Observable Tasks/Foundation/TaskSuccessPublisher.swift @@ -41,7 +41,19 @@ extension ObservableTask { /// - throws: An error indicating task failure or task cancellation. public var value: Success { get async throws { - try await successPublisher.output() + do { + let result: Success = try await successPublisher.output() + + return result + } catch { + if let error = error as? ObservableTaskFailureProtocol { + if let unwrappedError: any Swift.Error = error._opaque_error { + throw unwrappedError + } + } + + throw error + } } } } diff --git a/Sources/Merge/Intramodular/Observable Tasks/Status/ObservableTaskFailure.swift b/Sources/Merge/Intramodular/Observable Tasks/Status/ObservableTaskFailure.swift index ba68ae5..259e52e 100644 --- a/Sources/Merge/Intramodular/Observable Tasks/Status/ObservableTaskFailure.swift +++ b/Sources/Merge/Intramodular/Observable Tasks/Status/ObservableTaskFailure.swift @@ -6,6 +6,21 @@ import Diagnostics import Combine import Swallow +protocol ObservableTaskFailureProtocol { + var _opaque_error: (any Swift.Error)? { get } +} + +extension ObservableTaskFailure: ObservableTaskFailureProtocol { + public var _opaque_error: (any Swift.Error)? { + switch self { + case .canceled: + return nil + case .error(let error): + return error + } + } +} + /// An enumeration that represents the source of task failure. @frozen public enum ObservableTaskFailure: _ErrorX, HashEquatable {