Skip to content

Commit 5aec0e7

Browse files
committed
Be more tolerant wrt errors
... fallback to default imp.
1 parent ceea911 commit 5aec0e7

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

Sources/DirectToSwiftUI/ViewModel/D2SDisplayGroup.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,13 @@ fileprivate func buildInitialFetchSpec<Object: ActiveRecordType>
317317
if (fs.sortOrderings?.count ?? 0) == 0 {
318318
fs.sortOrderings = dataSource.entity?.d2s.defaultSortOrderings ?? []
319319
}
320-
assert(fs.sortOrderings != nil && !(fs.sortOrderings?.isEmpty ?? true))
320+
#if os(macOS)
321+
if !(fs.sortOrderings != nil && !(fs.sortOrderings?.isEmpty ?? true)) {
322+
globalD2SLogger.error("got no sort orderings for fetchspec:", fs)
323+
}
324+
#else
325+
assert(fs.sortOrderings != nil && !(fs.sortOrderings?.isEmpty ?? true))
326+
#endif
321327

322328
if let aux = auxiliaryQualifier {
323329
fs.qualifier = aux.and(fs.qualifier)

Sources/DirectToSwiftUI/Views/BasicLook/PageWrapper/EntityMasterDetailPage.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ public extension BasicLook.PageWrapper.MasterDetail {
2323
private var selectedEntity: Entity? {
2424
guard let entityName = selectedEntityName else { return nil }
2525
guard let entity = model[entity: entityName] else {
26-
fatalError("did not find entity: \(entityName) in \(model)")
26+
#if os(macOS)
27+
globalD2SLogger.error("did not find entity:", entityName,
28+
"in:", model)
29+
return nil
30+
#else
31+
fatalError("did not find entity: \(entityName) in \(model)")
32+
#endif
2733
}
2834
return entity
2935
}
@@ -71,7 +77,8 @@ public extension BasicLook.PageWrapper.MasterDetail {
7177
}
7278
else {
7379
EntityContent()
74-
.environment(\.entity, selectedEntity!)
80+
.environment(\.entity,
81+
selectedEntity ?? D2SKeys.entity.defaultValue)
7582
}
7683
}
7784
.frame(minWidth: 400 as CGFloat, idealWidth: 600 as CGFloat,

Sources/DirectToSwiftUI/Views/BasicLook/PageWrapper/EntitySidebar.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ public extension BasicLook.PageWrapper.MasterDetail.EntityMasterDetailPage {
6868
EntityName()
6969
Spacer()
7070
}
71-
.environment(\.entity, { self.model[entity: name]! }())
71+
.environment(\.entity, {
72+
self.model[entity: name] ?? D2SKeys.entity.defaultValue
73+
}())
7274
.frame(maxWidth: .infinity, maxHeight: .infinity)
7375
.foregroundColor(self.colorForEntityName(name))
7476
.onTapGesture {

0 commit comments

Comments
 (0)