fix(storage): refuse to open a workspace whose database file is missing

With .ykanban present but ykanban.db gone, opening used to create an empty
database and show an empty board without any hint. It now throws
WorkspaceDatabaseMissingException and shows the open-failed page, telling the
user to restore a backup or delete .ykanban and initialize again.
This commit is contained in:
doyaGu committed 2026-10-03 08:12:53 -04:00
1 parent 22102cd1ea
commit c12408d2e3
9 files changed
+65 -3

No files matched your search

@@ -89,4 +89,19 @@ public class WorkspaceSessionTests
Assert.ThrowsExactly<InvalidOperationException>(() => WorkspaceSession.Initialize(directory.FullPath));
using WorkspaceSession reopened = WorkspaceSession.Open(directory.FullPath);
}
[TestMethod]
public void OpenWithMissingDatabaseThrowsAndCreatesNothing()
{
using var directory = new TempDirectory();
WorkspaceInitializer.Initialize(directory.FullPath);
string databasePath = WorkspacePaths.Database(directory.FullPath);
File.Delete(databasePath);
Assert.ThrowsExactly<WorkspaceDatabaseMissingException>(() => WorkspaceSession.Open(directory.FullPath));
Assert.IsFalse(File.Exists(databasePath));
// The lock was released again: the next attempt fails the same way, not with a lock conflict.
Assert.ThrowsExactly<WorkspaceDatabaseMissingException>(() => WorkspaceSession.Open(directory.FullPath));
}
}
@@ -43,6 +43,9 @@ public class OpenFailedPageViewModelTests
Assert.AreEqual(
Expected(Resources.Error_OpenFailed_SchemaTooNew, 3L, 1),
OpenFailedPageViewModel.BuildMessage(Folder, new SchemaVersionException(3, 1)));
Assert.AreEqual(
Expected(Resources.Error_OpenFailed_DatabaseMissing),
OpenFailedPageViewModel.BuildMessage(Folder, new WorkspaceDatabaseMissingException("/work/repo/.ykanban/ykanban.db")));
Assert.AreEqual(
Expected(Resources.Error_OpenFailed_Database),
OpenFailedPageViewModel.BuildMessage(Folder, new SqliteException("file is not a database", 26)));