Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(sqlite): attribute unknown column selections to columns
Every worker "selection" rejection was projected onto the table argument,
including an exact column name that does not exist in an existing table.
Give column rejections their own worker reason and map each input reason
to the caller argument it requires correcting. Table rejections keep the
table path.

Fixes #2613

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Loading branch information
yasshmittal and claude committed Oct 13, 2026
commit b543e14ef02ffd8564876ee352880118b008e13a
2 changes: 1 addition & 1 deletion src/sqlite/SqliteDatabaseInspection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ const readRows = (
for (const name of columns)
if (!available.has(name))
throw new SqliteInspectionFailure(
"selection",
"column-selection",
`Selected column does not exist with that exact name in table ${input.table}: ${name}`,
);
const projection = columns
Expand Down
1 change: 1 addition & 0 deletions src/sqlite/SqliteDatabaseLimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class SqliteInspectionFailure extends Error {
readonly reason:
| "format"
| "selection"
| "column-selection"
| "unsupported"
| "unavailable"
| "output-limit"
Expand Down
11 changes: 10 additions & 1 deletion src/sqlite/SqliteDatabaseWorkerExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const replySchema = z.discriminatedUnion("ok", [
reason: z.enum([
"format",
"selection",
"column-selection",
"unsupported",
"unavailable",
"output-limit",
Expand All @@ -49,6 +50,14 @@ export type SqliteWorkerLauncher = NonNullable<
Parameters<typeof runOwnedCommand>[2]
>["launcher"];

// Each input rejection names the caller argument that requires correction.
const rejectedArgument = {
format: "path",
unsupported: "path",
selection: "table",
"column-selection": "columns",
} as const;

const rejectedReply = (
reply: z.output<typeof replySchema> & { ok: false },
capturedOutput: AnalysisCapturedOutput,
Expand Down Expand Up @@ -83,7 +92,7 @@ const rejectedReply = (
);
return new AnalysisInputError(operation, { capturedOutput }, [
{
path: [reply.reason === "selection" ? "table" : "path"],
path: [rejectedArgument[reply.reason]],
reason: "invalid_format",
message: reply.message,
},
Expand Down
44 changes: 44 additions & 0 deletions tests/boundary/sqlite/sqliteDatabaseProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DatabaseSync } from "node:sqlite";
import { promisify } from "node:util";
import { fileURLToPath } from "node:url";
import { expect, it as nativeTest, onTestFinished } from "vitest";
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
import { SqliteDatabaseProvider } from "../../../src/sqlite/SqliteDatabaseProvider.js";
import { spawnOwnedProviderProcess } from "../../../src/process/ProviderProcess.js";
import { PrivateRuntimeRoot } from "../../../src/process/PrivateRuntimeRoot.js";
Expand Down Expand Up @@ -356,6 +357,49 @@ it("does not execute views when selecting rows", async () => {
});
});

it("attributes table and column selection failures to their own arguments", async () => {
const { database } = await createFixture();
const provider = createProvider();
onTestFinished(() => provider.close());
const projection = async (selection: {
table: string;
columns?: string[];
}) => {
const result = await provider.inspect({
path: database.path,
row_limit: 1,
...selection,
});
if (result.ok) throw new Error("Expected a rejected selection");
return projectAnalysisError(result.error);
};
expect(
await projection({ table: "records", columns: ["nope"] }),
).toMatchObject({
details: {
issues: [
{
path: ["columns"],
reason: "invalid_format",
message:
"Selected column does not exist with that exact name in table records: nope",
},
],
},
});
expect(await projection({ table: "absent" })).toMatchObject({
details: { issues: [{ path: ["table"] }] },
});
const selected = await provider.inspect({
path: database.path,
table: "records",
columns: ["id"],
row_limit: 1,
});
if (!selected.ok) throw selected.error;
expect(selected.value.result).toMatchObject({ rows: { columns: ["id"] } });
});

it("rejects malformed databases without altering the selected file", async () => {
const workspace = await createTestWorkspace("rea-sqlite-invalid-");
onTestFinished(() => removeTestWorkspace(workspace.root));
Expand Down