Skip to content

fix(persistence): throw DuplicateCollectionNameException when adding a taken name - #385

Merged
mohamede1945 merged 1 commit into
mainfrom
fix/add-collection-duplicate-name
Nov 6, 2026
Merged

mohamede1945 merged 1 commit into
mainfrom
fix/add-collection-duplicate-name

Conversation

@mohamede1945

Copy link
Copy Markdown
Collaborator

Problem

When another collection already had the name (trimmed, case-insensitive), addCollection returned that collection, while updateCollection threw DuplicateCollectionNameException. Apps couldn't tell a create from a no-op. On iOS, creating "Study" when "Study" existed closed the name alert with no feedback. quran/quran-ios#1272 works around this by checking the collection IDs before creating, and that check leaves a small race.

Change

  • CollectionsRepositoryImpl.addCollection: inside the insert transaction, throws DuplicateCollectionNameException(existing.name) when store.byName finds a row. The checks run in the same order as updateCollection: reserved name, then length, then duplicate.
  • QuranDataService.addCollection: no code change. mutatingCall rethrows before triggerSync, so a rejected add starts no sync, and isRejection() already logs this exception at info.
  • The KDoc on CollectionsRepository and QuranDataService now lists the exception for add, and for update on the interface, which lacked it.
  • No internal path relied on the old behaviour: the import merger and highlight collections write through CollectionStore directly, and sync and remote apply go through CollectionsType.

Tests

  • CollectionNameUniquenessTest: adding a case or whitespace variant now throws with the stored name, and only one row stays.
  • TextScenariosTest TXT-08 and TXT-10: the second add now throws. TXT-08 still checks that the next sync posts nothing. TXT-10 still proves the leading BOM matches the same key, and it now also checks that the ideographic space is trimmed.
  • QuranDataServiceWriteLoggingTest: a new test checks that adding a taken name logs at info and triggers no sync.
  • ./gradlew jvmTest testAndroidHostTest --continue: passes.
  • The mobile-sync-spm integration tests pass against an XCFramework built from this branch.
  • quran-ios AnnotationsServiceTests and BookmarksFeatureTests pass in local-sync mode.
  • I didn't run iosSimulatorArm64Test / macosArm64Test locally.

Consumers

  • mobile-sync-spm: the companion PR updates the docs and adds an integration test. It needs the release that includes this change.
  • quran_android:
    • Already handled: the add-collection and add-tag flows map this exception to CollectionNameException.Duplicate.
    • Behaviour change: a case or whitespace variant used to quietly return the existing tag or collection. It now shows the duplicate-name error.
    • Breaks on upgrade: BookmarksDaoImplCollectionRulesTest "adding a tag whose name is taken returns the existing tag" uses the real repository, so it will need updating.

🤖 Generated with Claude Code

…a taken name

addCollection returned the existing collection when another one had the
name (trimmed, case-insensitive), while updateCollection threw
DuplicateCollectionNameException. Apps couldn't tell a create from a
no-op, so creating "Study" when "Study" existed closed the dialog with no
feedback.

addCollection now throws DuplicateCollectionNameException with the
existing name inside the insert transaction. A rejected add triggers no
sync and logs at info like the other collection rejections. Import and
highlight paths write through the store and are unaffected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mohamede1945
mohamede1945 merged commit fb1967e into main Nov 6, 2026
2 checks passed
@mohamede1945
mohamede1945 deleted the fix/add-collection-duplicate-name branch November 6, 2026 23:11
mohamede1945 added a commit to quran/mobile-sync-spm that referenced this pull request Nov 6, 2026
0.1.55 includes quran/mobile-sync#385, which makes addCollection throw
DuplicateCollectionNameException on a taken name. KMP-NativeCoroutines
stays at 1.0.6, matching native-coroutines in mobile-sync v0.1.55.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mohamede1945 added a commit to quran/mobile-sync-spm that referenced this pull request Nov 6, 2026
* docs: document the duplicate-name error from createCollection

mobile-sync's addCollection now throws DuplicateCollectionNameException
when another collection has the name (quran/mobile-sync#385), so
createCollection can throw MobileSyncDuplicateCollectionNameError.

Adds an integration test that creating " study " when "Study" exists
throws with the stored name and keeps a single Study.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* build(deps): update mobile-sync to 0.1.55

0.1.55 includes quran/mobile-sync#385, which makes addCollection throw
DuplicateCollectionNameException on a taken name. KMP-NativeCoroutines
stays at 1.0.6, matching native-coroutines in mobile-sync v0.1.55.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
mohamede1945 added a commit to quran/quran-ios that referenced this pull request Nov 6, 2026
Creating "Study" when "Study" existed closed the name alert with no
feedback, because MobileSync's createCollection returned the existing
collection instead of throwing.

mobile-sync now throws DuplicateCollectionNameException on a taken name
(quran/mobile-sync#385), which mapCollectionErrors already maps to
DuplicateCollectionNameError. Both create flows (Bookmarks and the
add-to-collection sheet) show that error in the name alert and keep the
typed name. This documents the error on createCollection and adds
regression tests for the service and both view models.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mohamede1945 added a commit to quran/quran-ios that referenced this pull request Nov 6, 2026
0.4.11 ships mobile-sync 0.1.55, where createCollection throws
MobileSyncDuplicateCollectionNameError when another collection has the
name (quran/mobile-sync#385, quran/mobile-sync-spm#51).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mohamede1945 added a commit to quran/quran-ios that referenced this pull request Nov 7, 2026
…ion (#1272)

* fix(bookmarks): show the duplicate-name error when creating a collection

Creating "Study" when "Study" existed closed the name alert with no
feedback, because MobileSync's createCollection returned the existing
collection instead of throwing.

mobile-sync now throws DuplicateCollectionNameException on a taken name
(quran/mobile-sync#385), which mapCollectionErrors already maps to
DuplicateCollectionNameError. Both create flows (Bookmarks and the
add-to-collection sheet) show that error in the name alert and keep the
typed name. This documents the error on createCollection and adds
regression tests for the service and both view models.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* build(deps): update mobile-sync-spm to 0.4.11

0.4.11 ships mobile-sync 0.1.55, where createCollection throws
MobileSyncDuplicateCollectionNameError when another collection has the
name (quran/mobile-sync#385, quran/mobile-sync-spm#51).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant