From 4c79127fcb31c5e85c4806f5a9522e00674f10e4 Mon Sep 17 00:00:00 2001 From: yasshmittal Date: Tue, 13 Oct 2026 19:18:39 +0530 Subject: [PATCH] fix(sqlite): classify a missing database path as an invalid value (#2775) * fix(sqlite): classify a missing database path as an invalid value The snapshot reported an absent selected database as an artifact path failure, which the adapter projects as invalid_format alongside malformed paths and content. The snapshot owns the absence observation, so it now returns an invalid_value input issue on path directly, matching the adapter's existing ENOENT/ENOTDIR classification. Fixes #2614 Co-Authored-By: Claude Opus 5.5 * fix(sqlite): classify a missing database path as an invalid value The snapshot reported an absent selected database as an artifact path failure, which the adapter projects as invalid_format alongside malformed paths and content. The snapshot owns the absence observation, so it now returns an invalid_value input issue on path directly, matching the adapter's existing ENOENT/ENOTDIR classification. Fixes #2614 Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 Co-authored-by: morluto <76467478+morluto@users.noreply.github.com> --- src/sqlite/SqliteDatabaseSnapshot.ts | 17 +++++++++---- .../sqlite/sqliteDatabaseProvider.test.ts | 24 +++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/sqlite/SqliteDatabaseSnapshot.ts b/src/sqlite/SqliteDatabaseSnapshot.ts index 4acf89611..1384fbdb6 100644 --- a/src/sqlite/SqliteDatabaseSnapshot.ts +++ b/src/sqlite/SqliteDatabaseSnapshot.ts @@ -3,6 +3,7 @@ import { constants, type BigIntStats } from "node:fs"; import { join } from "node:path"; import { ArtifactReaderFailure } from "../artifacts/ArtifactReader.js"; import type { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js"; +import { AnalysisInputError } from "../domain/analysisErrorCore.js"; import { OwnedFileHandle } from "../filesystem/OwnedFileHandle.js"; import { readStableArtifact, @@ -166,6 +167,16 @@ const verifyInactiveJournal = async ( } }; +// Absence is a caller value to correct, not malformed path or content. +const missingDatabase = (path: string): AnalysisInputError => + new AnalysisInputError("inspect_sqlite_database", undefined, [ + { + path: ["path"], + reason: "invalid_value", + message: `Selected SQLite database does not exist: ${path}`, + }, + ]); + /** Freeze a stable offline file set without ever opening the source through SQLite. */ export const captureSqliteDatabaseSnapshot = async ( path: string, @@ -183,11 +194,7 @@ export const captureSqliteDatabaseSnapshot = async ( const wal = before[1]; if (database === undefined || wal === undefined || before[2] === undefined) throw new Error("Incomplete database file-set observation"); - if (database === null) - throw new ArtifactReaderFailure( - "path", - `Selected SQLite database does not exist: ${path}`, - ); + if (database === null) throw missingDatabase(path); if (before[2] !== null) await verifyInactiveJournal( `${path}-journal`, diff --git a/tests/boundary/sqlite/sqliteDatabaseProvider.test.ts b/tests/boundary/sqlite/sqliteDatabaseProvider.test.ts index b5adf8297..7805552c9 100644 --- a/tests/boundary/sqlite/sqliteDatabaseProvider.test.ts +++ b/tests/boundary/sqlite/sqliteDatabaseProvider.test.ts @@ -357,6 +357,30 @@ it("does not execute views when selecting rows", async () => { }); }); +nativeTest.each(["absent.db", "absent-parent/absent.db"])( + "classifies a missing %s as an invalid value", + async (name) => { + const workspace = await createTestWorkspace("rea-sqlite-missing-"); + onTestFinished(() => removeTestWorkspace(workspace.root)); + const path = workspace.path(name); + const provider = createProvider(); + onTestFinished(() => provider.close()); + const result = await provider.inspect({ path }); + if (result.ok) throw new Error("Expected a missing database rejection"); + expect(projectAnalysisError(result.error)).toMatchObject({ + details: { + issues: [ + { + path: ["path"], + reason: "invalid_value", + message: `Selected SQLite database does not exist: ${path}`, + }, + ], + }, + }); + }, +); + it("attributes table and column selection failures to their own arguments", async () => { const { database } = await createFixture(); const provider = createProvider();