Skip to content

Fix crash when calling removeAll() on an in-memory LoggerStore#374

Open
denricklaborada wants to merge 1 commit into
kean:mainfrom
denricklaborada:fix/in-memory-loggerstore-crash
Open

Fix crash when calling removeAll() on an in-memory LoggerStore#374
denricklaborada wants to merge 1 commit into
kean:mainfrom
denricklaborada:fix/in-memory-loggerstore-crash

Conversation

@denricklaborada

Copy link
Copy Markdown

Summary

Fixes #373.

Calling removeAll() (e.g. tapping Remove Logs in ConsoleView) on a LoggerStore created with the .inMemory option crashes the app:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Unknown command type <NSBatchDeleteRequest ... entity: LoggerMessageEntity ...>'

Cause

removeAll()_removeAll()deleteEntities(for:) executes an NSBatchDeleteRequest. Batch requests operate directly against the backing SQLite store, bypassing the managed object context — they are only supported on NSSQLiteStoreType, not NSInMemoryStoreType. Since .inMemory configures the store as NSInMemoryStoreType (LoggerStore.makeContainer), Core Data has no handler for the batch command and throws.

Fix

Split deleteEntities(for:) into two paths:

  • SQLite stores keep using the efficient NSBatchDeleteRequest (unchanged).
  • In-memory stores fetch the matching objects, delete them individually via context.delete(_:), save, and merge the deletions into the view context.

Verification

Ran the demo app on an iPhone 17 Pro simulator, wired to an in-memory LoggerStore (matching the crashing setup), triggering removeAll() on a store populated with 20 messages:

  • Before the fix: reproduced the exact NSInternalInconsistencyException / Unknown command type <NSBatchDeleteRequest ...> crash.
  • After the fix: no crash; the store correctly went from 20 → 0 messages, with the deletion reflected in the view context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LoggerStore.removeAll() crashes with in-memory store option ("Unknown command type" NSBatchDeleteRequest)

1 participant