Skip to content

Commit

Permalink
Add breadcrumbs in the DataController initialization (#1111)
Browse files Browse the repository at this point in the history
* chore(swiftdata): add breadcrumbs in the data controller initialization

* chore(swiftdata): add breadcrumbs in the data controller initialization
  • Loading branch information
Gio2018 authored Nov 13, 2024
1 parent 2e23dc5 commit db838ea
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions PocketKit/Sources/Sync/SwiftData/DataController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import Foundation
import SwiftData
import SharedPocketKit

@MainActor
public class DataController {
Expand Down Expand Up @@ -46,19 +47,25 @@ public class DataController {
}()

public static let sharedModelContainer: ModelContainer = {
Log.breadcrumb(category: "SWiftData", level: .info, message: "Start initializing shared model container.")
ArticleTransformer.register()
Log.breadcrumb(category: "SWiftData", level: .info, message: "Article transformer registered.")
SyncTaskTransformer.register()
Log.breadcrumb(category: "SWiftData", level: .info, message: "SynkTask transformer registered.")

guard let appGroupContainerID = appGroupContainerID else {
Log.breadcrumb(category: "SwiftData", level: .fatal, message: "appGroupContainerID must be set before accessing the sharedModelContainer.")
fatalError("appGroupContainerID must be set before accessing the sharedModelContainer.")
}
guard let appGroupContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupContainerID) else {
Log.breadcrumb(category: "SwiftData", level: .fatal, message: "Shared file container could not be created.")
fatalError("Shared file container could not be created.")
}
let url = appGroupContainer.appendingPathComponent("PocketModel.sqlite")
do {
return try ModelContainer(for: schema, configurations: ModelConfiguration(url: url))
} catch {
Log.breadcrumb(category: "SwiftData", level: .fatal, message: "Could not create ModelContainer: \(error)")
fatalError("Could not create ModelContainer: \(error)")
}
}()
Expand Down

0 comments on commit db838ea

Please sign in to comment.