From 4971ccfdcf6bb4b6975b649f8b2eea18ecf1c5be Mon Sep 17 00:00:00 2001 From: Jamie Pine Date: Wed, 24 Sep 2025 04:50:48 -0700 Subject: [PATCH] feat: Enhance DaemonConnector and InspectorViewModel with Logging and Error Handling - Integrated OS logging into DaemonConnector and InspectorViewModel for improved traceability of operations. - Added detailed logging for query execution and file loading processes, enhancing debugging capabilities. - Introduced custom error handling in InspectorViewModel to manage file loading errors more effectively. - Updated query methods to log success and failure cases, providing better insights into application behavior. --- .../SpacedriveClient/SpacedriveClient.swift | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/swift-client/Sources/SpacedriveClient/SpacedriveClient.swift b/packages/swift-client/Sources/SpacedriveClient/SpacedriveClient.swift index 25d221e0e..d8b5c1f7d 100644 --- a/packages/swift-client/Sources/SpacedriveClient/SpacedriveClient.swift +++ b/packages/swift-client/Sources/SpacedriveClient/SpacedriveClient.swift @@ -751,11 +751,18 @@ extension SpacedriveClient { let response = try await sendRequest(.query(method: wireMethod, libraryId: getCurrentLibraryId(), payload: queryDict)) switch response { - case .jsonOk(let anyCodable): - // Convert AnyCodable to Data, then decode to File? - let data = try JSONEncoder().encode(anyCodable) - let result = try JSONDecoder().decode(File?.self, from: data) - return result + case .jsonOk(let jsonData): + print("🔍 Decoding File from JSON data: \(jsonData.value)") + do { + let jsonResponseData = try JSONSerialization.data(withJSONObject: jsonData.value) + let result = try JSONDecoder().decode(File.self, from: jsonResponseData) + print("✅ Successfully decoded File: \(result.name)") + return result + } catch { + print("❌ Failed to decode File: \(error)") + print("❌ JSON data: \(jsonData.value)") + throw SpacedriveError.invalidResponse("Failed to decode File: \(error)") + } case .error(let error): throw SpacedriveError.daemonError("Query failed: \(error)") default: