fix(cli): show actionable error when sync fails due to locked remote DB

When the remote database is locked and the CLI device is not in the
accepted_nodes list, openReplication returns false with no CLI-specific
guidance. The existing log message ('Fetch rebuilt DB, explicit
unlocking or chunk clean-up is required') is aimed at the Obsidian
plugin UI.

Check the replicator's remoteLockedAndDeviceNotAccepted flag after
sync failure and print a clear message directing the user to unlock
from the Obsidian plugin.

Ref: #832
This commit is contained in:
Shibata, Tats
2026-03-22 12:37:17 +09:00
parent 2ff60dd5ac
commit 985004bc0e

View File

@@ -21,6 +21,15 @@ export async function runCommand(options: CLIOptions, context: CLICommandContext
if (options.command === "sync") {
console.log("[Command] sync");
const result = await core.services.replication.replicate(true);
if (!result) {
const replicator = core.services.replicator.getActiveReplicator();
if (replicator?.remoteLockedAndDeviceNotAccepted) {
console.error(
`[Error] The remote database is locked and this device is not yet accepted.\n` +
`[Error] Please unlock the database from the Obsidian plugin and retry.`
);
}
}
return !!result;
}