Debugging help

No matter what I do, I keep getting the error Thread 1: EXC_BREAKPOINT (code=1, subcode=0x2648fc364) for the line: transactions = try modelContext.fetch(descriptor) in the code below. My app opens, but freezes on the home page and I can't click anything. I am not sure how to fix initialization issues. I am creating a financial assistant app that connects plaid and opoenai api.

var descriptor = FetchDescriptor<ExpenseTransaction>()
descriptor.sortBy = [SortDescriptor(\.date, order: .reverse)]
descriptor.fetchLimit = 200
transactions = try modelContext.fetch(descriptor)
print("Successfully loaded \(transactions.count) transactions")
} catch {
print("Error in loadLocalTransactions: \(error)")
transactions = []
}
}

Put the call to modelContext.fetch() inside a try { ... } catch { ... } block, and print out the error that it catches.

If you're trying to do something but you aren't bothering to catch any errors to see why it's failing, you're going to hit issues like this.

Your current code is always assuming that everything is 100% tickety-boo all the time. If transactions was nil, the call to transaction.count would crash the app anyway.

What @darkpaw said. If you can catch and provide the detailed error message, folks here may be able to comment.

If you can't catch anything, which can happen in some cases, a minimal project that reproduces the issue will help as well. Your post can contain a link to where your test project is hosted.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Debugging help
 
 
Q