fix(query): preserve structured backend errors

This commit is contained in:
miracle authored and GitHub committed 2026-08-02 16:37:46 +08:00
1 parent 2e9dcdc26b
commit bcafc4a474
58 files changed
+4182 -554

No files matched your search

@@ -14,29 +14,30 @@ function dataResult(columns: string[]): QueryResult {
describe("isNoSnapshotErrorResult", () => {
it("matches the StarRocks Paimon no-snapshot error surfaced via executeTabSql", () => {
const result = errorResult("Server error: `ERROR HY000 (1064): There is currently no snapshot.`");
const result = { ...errorResult("Server error: `ERROR HY000 (1064): There is currently no snapshot.`"), execution_error: true as const };
expect(isNoSnapshotErrorResult(result)).toBe(true);
});
it("matches case-insensitively", () => {
const result = errorResult("there IS currently NO snapshot");
const result = { ...errorResult("there IS currently NO snapshot"), execution_error: true as const };
expect(isNoSnapshotErrorResult(result)).toBe(true);
});
it("does not match unrelated query errors", () => {
expect(isNoSnapshotErrorResult(errorResult("Unknown table 'tag_test.record_tag_t'"))).toBe(false);
expect(isNoSnapshotErrorResult(errorResult("ERROR 1142: SELECT command denied"))).toBe(false);
expect(isNoSnapshotErrorResult({ ...errorResult("Unknown table 'tag_test.record_tag_t'"), execution_error: true })).toBe(false);
expect(isNoSnapshotErrorResult({ ...errorResult("ERROR 1142: SELECT command denied"), execution_error: true })).toBe(false);
});
it("does not match successful data results", () => {
expect(isNoSnapshotErrorResult(dataResult(["id", "name"]))).toBe(false);
expect(isNoSnapshotErrorResult(dataResult(["Error"]))).toBe(false); // data column literally named Error, no rows
expect(isNoSnapshotErrorResult({ ...errorResult("There is currently no snapshot."), rows: [["There is currently no snapshot."]] })).toBe(false);
});
it("returns false for missing or empty results", () => {
expect(isNoSnapshotErrorResult(undefined)).toBe(false);
expect(isNoSnapshotErrorResult(null)).toBe(false);
expect(isNoSnapshotErrorResult({ ...errorResult("There is currently no snapshot."), rows: [] })).toBe(false);
expect(isNoSnapshotErrorResult({ ...errorResult("There is currently no snapshot."), execution_error: true, rows: [] })).toBe(false);
});
});
@@ -60,11 +60,17 @@ describe("SQL Server explain plan", () => {
});
it("surfaces a SQL Server batch error instead of treating it as a plan", () => {
expect(sqlServerExplainResult([result(["Error"], [["Invalid object name 'missing_table'"]])])).toEqual({
expect(sqlServerExplainResult([{ ...result(["Error"], [["Invalid object name 'missing_table'"]]), execution_error: true }])).toEqual({
error: "Invalid object name 'missing_table'",
});
});
it("does not mistake a successful Error column for a SQL Server batch failure", () => {
expect(sqlServerExplainResult([result(["Error"], [["valid query value"]])])).toEqual({
error: "SQL Server did not return ShowPlan XML",
});
});
it("rejects malformed SHOWPLAN XML", () => {
const malformed = result(["Microsoft SQL Server 2005 XML Showplan"], [["<ShowPlanXML><RelOp></ShowPlanXML>"]]);
+13 -1
View File
@@ -1,7 +1,7 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createPinia, setActivePinia } from "pinia";
import { useConnectionStore } from "@/stores/connectionStore";
import { connectionGroupDisplayName, middleEllipsis, queryResultBaseSql, queryResultExecutionSql, resultSourceRange, statementExecutionMarkers, tabTooltipLines, tabularResultItems } from "@/lib/tabs/tabPresentation";
import { connectionGroupDisplayName, executionSummaryItems, middleEllipsis, queryResultBaseSql, queryResultExecutionSql, resultSourceRange, statementExecutionMarkers, tabTooltipLines, tabularResultItems } from "@/lib/tabs/tabPresentation";
import { sqlTextFingerprint } from "@/lib/sql/sqlTextFingerprint";
import type { ConnectionConfig, QueryTab } from "@/types/database";
@@ -224,6 +224,18 @@ describe("query result source ranges", () => {
});
});
describe("execution summary", () => {
it("uses the explicit execution marker instead of the result column name", () => {
const successfulAlias = { columns: ["Error"], rows: [[2]], affected_rows: 0, execution_time_ms: 1 };
const markedFailure = { columns: ["Error"], rows: [["failed"]], affected_rows: 0, execution_time_ms: 1, execution_error: true as const };
expect(executionSummaryItems({ results: [successfulAlias, markedFailure] }).map(({ status, isError }) => ({ status, isError }))).toEqual([
{ status: "success", isError: false },
{ status: "error", isError: true },
]);
});
});
describe("statement execution markers", () => {
it("renders a live marker for a single statement", () => {
const sql = "SELECT 1";