diff --git a/Package.swift b/Package.swift index 8b077ce8..45354ee5 100644 --- a/Package.swift +++ b/Package.swift @@ -31,7 +31,12 @@ let package = Package( .package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.0.0"), ], targets: [ - .target(name: "_Helpers"), + .target( + name: "_Helpers", + dependencies: [ + .product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"), + ] + ), .target(name: "Functions", dependencies: ["_Helpers"]), .testTarget( name: "FunctionsTests", diff --git a/Sources/PostgREST/PostgrestBuilder.swift b/Sources/PostgREST/PostgrestBuilder.swift index 98c5b471..539eba35 100644 --- a/Sources/PostgREST/PostgrestBuilder.swift +++ b/Sources/PostgREST/PostgrestBuilder.swift @@ -71,7 +71,12 @@ public class PostgrestBuilder: @unchecked Sendable { } return try await execute { [configuration] data in - try configuration.decoder.decode(T.self, from: data) + do { + return try configuration.decoder.decode(T.self, from: data) + } catch { + debug("Fail to decode type '\(T.self) with error: \(error)") + throw error + } } } diff --git a/Sources/Supabase/Types.swift b/Sources/Supabase/Types.swift index 270fea27..44fffe51 100644 --- a/Sources/Supabase/Types.swift +++ b/Sources/Supabase/Types.swift @@ -13,7 +13,11 @@ public struct SupabaseClientOptions: Sendable { public let encoder: JSONEncoder public let decoder: JSONDecoder - public init(schema: String = "public", encoder: JSONEncoder = .postgrest, decoder: JSONDecoder = .postgrest) { + public init( + schema: String = "public", + encoder: JSONEncoder = .postgrest, + decoder: JSONDecoder = .postgrest + ) { self.schema = schema self.encoder = encoder self.decoder = decoder diff --git a/Sources/_Helpers/Logger.swift b/Sources/_Helpers/Logger.swift new file mode 100644 index 00000000..36a4a186 --- /dev/null +++ b/Sources/_Helpers/Logger.swift @@ -0,0 +1,36 @@ +// +// Logger.swift +// +// +// Created by Guilherme Souza on 11/12/23. +// + +import ConcurrencyExtras +import Foundation + +private let _debugLoggingEnabled = LockIsolated(false) +@_spi(Internal) public var debugLoggingEnabled: Bool { + get { _debugLoggingEnabled.value } + set { _debugLoggingEnabled.setValue(newValue) } +} + +private let standardError = LockIsolated(FileHandle.standardError) +@_spi(Internal) public func debug( + _ message: @autoclosure () -> String, + function: String = #function, + file: String = #file, + line: UInt = #line +) { + assert( + { + if debugLoggingEnabled { + standardError.withValue { + let logLine = "[\(function) \(file.split(separator: "/").last!):\(line)] \(message())\n" + $0.write(Data(logLine.utf8)) + } + } + + return true + }() + ) +}