Skip to content

Commit

Permalink
Showing 4 changed files with 53 additions and 3 deletions.
7 changes: 6 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -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",
7 changes: 6 additions & 1 deletion Sources/PostgREST/PostgrestBuilder.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
}

6 changes: 5 additions & 1 deletion Sources/Supabase/Types.swift
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions Sources/_Helpers/Logger.swift
Original file line number Diff line number Diff line change
@@ -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
}()
)
}

0 comments on commit e5f1e4b

Please sign in to comment.