Skip to content

Feature: Improve UX when importing vaults with invalid structure - #4243

Merged
infeo merged 9 commits into
developfrom
feature/not-a-vault-dir
Jun 10, 2026
Merged

infeo merged 9 commits into
developfrom
feature/not-a-vault-dir

Conversation

@infeo

@infeo infeo commented Jun 2, 2026 •

Copy link
Copy Markdown
Member

This PR enhances the UX when an invalid vault is imported.

If the user imports a vault (drag'n'drop, import vault dialog, file association), the vault might be invalid (missing directory, no read access, etc...). We already do a test, but it is encapsulated inside cryptofs only saying "vault, legacy, none" without giving any reason. The user or the support employee needs more information.

Currently, the generic error window is shown, i.e.:

Error Code O52V:SEG2:SEG2
java.nio.file.NoSuchFileException: C:\Users\somePerson\Desktop\Cryptomator: Not a vault directory
	at [email protected]/org.cryptomator.common.vaults.VaultListManager.add(VaultListManager.java:78)
	at [email protected]/org.cryptomator.ui.addvaultwizard.ChooseExistingVaultController.chooseFileAndNext(ChooseExistingVaultController.java:87)
...(many more FX calls)

This is fixed by getting a "bad" result in the check analyzes the faulty vault more and displaying a helpful message. All three import user interactions (drag+drop, import dialog, file association) are adjusted to this.

@infeo infeo self-assigned this Jun 2, 2026
@infeo infeo added this to the next milestone Jun 2, 2026
@coderabbitai

coderabbitai Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d98d7be3-2068-49b9-af1c-6b1c523a2bc1

📥 Commits

Reviewing files that changed from the base of the PR and between 719a916 and 64b0e63.

📒 Files selected for processing (1)
  • src/main/java/org/cryptomator/common/vaults/VaultListManager.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/cryptomator/common/vaults/VaultListManager.java

Walkthrough

This PR introduces vault directory validation with structured error reporting. A new NotAVaultDirectoryException type with a Reason enum replaces generic error handling. The VaultListManager gains assertIsVaultDirectory() that validates data directory and config file presence/readability. Vault addition is made thread-safe by conditionally scheduling list mutations to the FX thread. Three UI controllers—ChooseExistingVaultController, AppLaunchEventHandler, and VaultListController—now catch the exception and display a localized error dialog via Dialogs.prepareNotAVaultDirectoryDialog(). Supporting tests verify all validation failure modes and success paths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: improving UX when importing vaults with invalid structure.
Description check ✅ Passed The description is clearly related to the changeset, explaining the problem, solution, and impact of the invalid vault import handling.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/not-a-vault-dir

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java (1)

303-314: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Drag-and-drop still bypasses the new invalid-vault dialog.

This path only forwards entries where containsVault(...) returns true, but containsVault(...) rejects DirStructure.UNRELATED. That is the exact branch where VaultListManager.assertIsVaultDirectory(...) now performs the detailed checks and throws NotAVaultDirectoryException, so invalid vault directories are still ignored here instead of showing the new error dialog.

Also applies to: 321-326

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java` around
lines 303 - 314, handleDragEvent currently filters dropped files using
containsVault(...) which returns false for DirStructure.UNRELATED and thus skips
paths that should trigger VaultListManager.assertIsVaultDirectory(...) and
display the NotAVaultDirectoryException dialog; update handleDragEvent (and the
similar branch handling at the other drop location) to collect candidate paths
from the dragboard without pre-filtering by containsVault, then for each
candidate call VaultListManager.assertIsVaultDirectory(...) inside a try/catch
that on success calls addVault(...) and on NotAVaultDirectoryException shows the
new invalid-vault dialog; also ensure draggingVaultOver logic uses a
light-weight predicate (or a separate quick check) to decide acceptTransferModes
but do not suppress paths that must produce the error dialog.
🧹 Nitpick comments (1)
src/test/java/org/cryptomator/common/vaults/VaultListManagerTest.java (1)

19-68: ⚡ Quick win

Add coverage for the remaining reason branches.

The suite never exercises VAULT_CONFIG_ACCESS_DENIED or UNSUPPORTED_STRUCTURE, even though both now drive user-facing error messages. A targeted regression test for each would make the new validation contract much harder to break silently.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/test/java/org/cryptomator/common/vaults/VaultListManagerTest.java` around
lines 19 - 68, Add two unit tests that exercise the
NotAVaultDirectoryException.Reason.VAULT_CONFIG_ACCESS_DENIED and
.UNSUPPORTED_STRUCTURE branches by calling
VaultListManager.assertIsVaultDirectory: for VAULT_CONFIG_ACCESS_DENIED create
the DATA_DIR_NAME and VAULTCONFIG_FILENAME but make the vault config file
unreadable (use Files.setPosixFilePermissions or equivalent setup so reading the
config triggers an access-denied path) and assert the thrown exception's
notAVaultReason() is VAULT_CONFIG_ACCESS_DENIED; for UNSUPPORTED_STRUCTURE
create a DATA_DIR_NAME and a combination of files/dirs that match the
legacy/modern check failure scenario (e.g. a file structure that prevents
locating VAULTCONFIG_FILENAME or MASTERKEY_FILENAME as expected) and assert the
thrown reason is UNSUPPORTED_STRUCTURE; reference
VaultListManager.assertIsVaultDirectory, NotAVaultDirectoryException.Reason,
VAULTCONFIG_FILENAME, MASTERKEY_FILENAME and DATA_DIR_NAME when adding the
tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/java/org/cryptomator/common/vaults/VaultListManager.java`:
- Around line 92-100: The add(Path) method in VaultListManager performs the
existence check off the FX thread but only enqueues vaultList.add(...) on the FX
thread, allowing race conditions where multiple callers add duplicates; fix by
making the check+add atomic on the FX thread—either move the get(...) and add
logic into a single Platform.runLater block that calls addVault(newVault) (which
uses isAlreadyAdded(...)) so the presence check and add occur together, or guard
against concurrent adds by introducing a concurrent Set of pending paths
checked/updated around newVault creation and before enqueueing
Platform.runLater; ensure you reference VaultListManager.add(Path),
newVaultSettings(...), addVault(Vault), isAlreadyAdded(...), Platform.runLater
and vaultList.add(newVault) when making the change.
- Around line 123-132: In VaultListManager.checkConfigFile, don’t map every
IOException to VAULT_CONFIG_ACCESS_DENIED; instead update the exception handling
around opening/reading vaultConfig (resolved from VAULTCONFIG_FILENAME) to
distinguish AccessDeniedException -> throw NotAVaultDirectoryException(...,
Reason.VAULT_CONFIG_ACCESS_DENIED), NoSuchFileException -> throw
NotAVaultDirectoryException(..., Reason.MISSING_VAULT_CONFIG), and any other
IOException -> throw NotAVaultDirectoryException(...,
Reason.UNSUPPORTED_STRUCTURE) (or the appropriate Reason for unexpected IO
errors), keeping the initial exists() check but accounting for race conditions
by relying on these specific catches in the try-with-resources block inside
checkConfigFile.

In `@src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java`:
- Around line 332-344: The async add can enqueue duplicates because two tasks
can concurrently call vaultListManager.add(target) after normalization; fix by
making the existence-check-and-add atomic: either (A) perform the
check-and-schedule on the FX thread (use Platform.runLater to check
vaultListManager.get(normalizedTarget) and only call
vaultListManager.add(normalizedTarget) / vaultList.add(...) if absent) or (B)
add an atomic/thread-safe method to VaultListManager (e.g., addIfAbsent(Path) or
synchronize inside VaultListManager.add so it checks get(normalizedPath) and
enqueues the vault on the FX thread in one synchronized/atomic operation) and
call that from addVault via the executor. Ensure you reference the normalized
target (the local variable target) when performing the check so duplicates are
detected before enqueuing.

---

Outside diff comments:
In `@src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java`:
- Around line 303-314: handleDragEvent currently filters dropped files using
containsVault(...) which returns false for DirStructure.UNRELATED and thus skips
paths that should trigger VaultListManager.assertIsVaultDirectory(...) and
display the NotAVaultDirectoryException dialog; update handleDragEvent (and the
similar branch handling at the other drop location) to collect candidate paths
from the dragboard without pre-filtering by containsVault, then for each
candidate call VaultListManager.assertIsVaultDirectory(...) inside a try/catch
that on success calls addVault(...) and on NotAVaultDirectoryException shows the
new invalid-vault dialog; also ensure draggingVaultOver logic uses a
light-weight predicate (or a separate quick check) to decide acceptTransferModes
but do not suppress paths that must produce the error dialog.

---

Nitpick comments:
In `@src/test/java/org/cryptomator/common/vaults/VaultListManagerTest.java`:
- Around line 19-68: Add two unit tests that exercise the
NotAVaultDirectoryException.Reason.VAULT_CONFIG_ACCESS_DENIED and
.UNSUPPORTED_STRUCTURE branches by calling
VaultListManager.assertIsVaultDirectory: for VAULT_CONFIG_ACCESS_DENIED create
the DATA_DIR_NAME and VAULTCONFIG_FILENAME but make the vault config file
unreadable (use Files.setPosixFilePermissions or equivalent setup so reading the
config triggers an access-denied path) and assert the thrown exception's
notAVaultReason() is VAULT_CONFIG_ACCESS_DENIED; for UNSUPPORTED_STRUCTURE
create a DATA_DIR_NAME and a combination of files/dirs that match the
legacy/modern check failure scenario (e.g. a file structure that prevents
locating VAULTCONFIG_FILENAME or MASTERKEY_FILENAME as expected) and assert the
thrown reason is UNSUPPORTED_STRUCTURE; reference
VaultListManager.assertIsVaultDirectory, NotAVaultDirectoryException.Reason,
VAULTCONFIG_FILENAME, MASTERKEY_FILENAME and DATA_DIR_NAME when adding the
tests.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0f4e0525-9194-47ee-9302-03ba4ee09aa2

📥 Commits

Reviewing files that changed from the base of the PR and between d5d992b and 719a916.

📒 Files selected for processing (8)
  • src/main/java/org/cryptomator/common/vaults/NotAVaultDirectoryException.java
  • src/main/java/org/cryptomator/common/vaults/VaultListManager.java
  • src/main/java/org/cryptomator/ui/addvaultwizard/ChooseExistingVaultController.java
  • src/main/java/org/cryptomator/ui/dialogs/Dialogs.java
  • src/main/java/org/cryptomator/ui/fxapp/AppLaunchEventHandler.java
  • src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java
  • src/main/resources/i18n/strings.properties
  • src/test/java/org/cryptomator/common/vaults/VaultListManagerTest.java

@infeo

infeo commented Jun 3, 2026

Copy link
Copy Markdown
Member Author

Test results from UI test:

Scenario Result with 1.19.2 Result with feature-branch
ChooseExisting, NoD generic "not a vault directory" dialog Showing specific error dialog
ChooseExisting, FileD generic "not a vault directory" dialog Showing specific error dialog
ChooseExisting, ReadOnlyConfig Windows Explorer does not allow to "open" it Windows Explorer does not allow to "open" it
ChooseExisting, NoConfig Vault can be imported, Vault Config is missing in Vault details Vault can be imported, Vault Config is missing in Vault details
ChooseExisting, Nothing generic "not a vault directory" dialog Showing specific error dialog
Drag'n'Drop, NoD Cannot drop cannot be dropped
Drag'n'Drop, FileD Cannot be dropped cannot be dropped
Drag'n'Drop, ReadOnlyConfig Vault can be imported, showing AccessDenied error Vault can be imported, showing AccessDenied error
Drag'n'Drop, NoConfig Vault can be imported, Vault Config is missing in Vault details Vault can be imported, Vault Config is missing in Vault details
Drag'n'Drop, Nothing Cannot be dropped cannot be dropped
AppLaunchEvent, NoD Nothing, only mainWindow opens Showing specific error dialog
AppLaunchEvent, FileD Nothing, only mainWindow opens Showing specific error dialog
AppLaunchEvent, ReadOnlyConfig Vault can be imported, showing AccessDenied error Vault can be imported, showing AccessDenied error
AppLaunchEvent, NoConfig Vault can be imported, Vault Config is missing in Vault details Vault can be imported, Vault Config is missing in Vault details
AppLaunchEvent, Nothing Nothing, only mainWindow opens Showing specific error dialog

Overall an improvement, no regressions.

@infeo
infeo merged commit 331f66d into develop Jun 10, 2026
26 of 27 checks passed
@infeo
infeo deleted the feature/not-a-vault-dir branch June 10, 2026 09:24
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