Skip to content

Commit

Permalink
Merge pull request #299 from rounak/har-crash-fix
Browse files Browse the repository at this point in the history
Fix crash when exporting HAR file
  • Loading branch information
kean authored Oct 4, 2024
2 parents 2a0d1f5 + 3dd1cbd commit efac97a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions Sources/Pulse/LoggerStore/LoggerStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,10 @@ extension LoggerStore {
/// - parameter predicate: By default, `nil`.
public func messages(
sortDescriptors: [SortDescriptor<LoggerMessageEntity>] = [SortDescriptor(\.createdAt, order: .forward)],
predicate: NSPredicate? = nil
predicate: NSPredicate? = nil,
context: NSManagedObjectContext? = nil
) throws -> [LoggerMessageEntity] {
try viewContext.fetch(LoggerMessageEntity.self) {
try (context ?? viewContext).fetch(LoggerMessageEntity.self) {
$0.sortDescriptors = sortDescriptors.map(NSSortDescriptor.init)
$0.predicate = predicate
}
Expand All @@ -781,9 +782,10 @@ extension LoggerStore {
/// - parameter predicate: By default, `nil`.
public func tasks(
sortDescriptors: [SortDescriptor<NetworkTaskEntity>] = [SortDescriptor(\.createdAt, order: .forward)],
predicate: NSPredicate? = nil
predicate: NSPredicate? = nil,
context: NSManagedObjectContext? = nil
) throws -> [NetworkTaskEntity] {
try viewContext.fetch(NetworkTaskEntity.self) {
try (context ?? viewContext).fetch(NetworkTaskEntity.self) {
$0.sortDescriptors = sortDescriptors.map(NSSortDescriptor.init)
$0.predicate = predicate
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/PulseUI/Helpers/HARDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct HARDocument: Encodable {
init(store: LoggerStore) throws {
var entries: [Entry] = []
var pages: [Page] = []
try Dictionary(grouping: store.tasks(), by: \.url).values.forEach { networkTasks in
try Dictionary(grouping: store.tasks(context: store.backgroundContext), by: \.url).values.forEach { networkTasks in
let pageId = "page_\(pages.count)"
pages.append(
.init(
Expand All @@ -29,7 +29,7 @@ struct HARDocument: Encodable {
)
entries.append(contentsOf: networkTasks.map { .init(entity: $0, pageId: pageId) })
}
try store.messages().forEach { message in
try store.messages(context: store.backgroundContext).forEach { message in
if let task = message.task {
entries.append(.init(entity: task, pageId: "page_\(pages.count)"))
}
Expand Down

0 comments on commit efac97a

Please sign in to comment.