Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: improve error style (#13588)

Liu Ji3a0ba874b8d4
diff --git a/frontend/src/components/MonacoEditor/utils.ts b/frontend/src/components/MonacoEditor/utils.ts
index 06bb656219..39d8d1d22d 100644
--- a/frontend/src/components/MonacoEditor/utils.ts
+++ b/frontend/src/components/MonacoEditor/utils.ts
@@ -7,7 +7,7 @@ import type { Language, MaybeRef, SQLDialect } from "@/types";
import { minmax } from "@/utils";
import LearnMoreLink from "../LearnMoreLink.vue";
import sqlFormatter from "./sqlFormatter";
-import type { IStandaloneCodeEditor } from "./types";
+import type { IStandaloneCodeEditor, Selection } from "./types";
// Max retires in a retry serial. Will be reset after a success connection
export const MAX_RETRIES = 5;
@@ -150,3 +150,15 @@ export const progressiveDelay = (serial: number) => {
RECONNECTION_DELAY.max
);
};
+
+export const positionWithOffset = (
+ line: number,
+ column: number,
+ selection?: Selection | undefined | null
+) => {
+ if (!selection || selection.isEmpty()) {
+ return [line, column];
+ }
+ const pos = selection.getStartPosition().delta(line - 1, column);
+ return [pos.lineNumber, pos.column - 1];
+};
diff --git a/frontend/src/composables/useExecuteSQL.ts b/frontend/src/composables/useExecuteSQL.ts
index ebbfdb78d7..4f08937094 100644
--- a/frontend/src/composables/useExecuteSQL.ts
+++ b/frontend/src/composables/useExecuteSQL.ts
@@ -270,7 +270,7 @@ const useExecuteSQL = () => {
);
if (errorAdvice) {
notifyAdvices(advices);
- return abort(errorAdvice.content);
+ return abort(errorAdvice.content, advices);
}
}
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView/AdviceItem.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView/AdviceItem.vue
new file mode 100644
index 0000000000..5172dc0e98
--- /dev/null
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView/AdviceItem.vue
@@ -0,0 +1,82 @@
+<template>
+ <div
+ class="grid items-start gap-2 text-sm p-1"
+ style="grid-template-columns: auto 1fr"
+ >
+ <div class="shrink-0 flex items-center h-5">
+ <CircleAlertIcon
+ v-if="advice.status === Advice_Status.ERROR"
+ class="w-5 h-5 text-error"
+ />
+ <CircleAlertIcon
+ v-if="advice.status === Advice_Status.WARNING"
+ class="w-5 h-5 text-warning"
+ />
+ </div>
+ <div class="flex items-center gap-1">
+ <span>{{ title }}</span>
+ <NButton size="tiny" quaternary type="primary" @click="doScroll">
+ L{{ position.startLine }}:C{{ position.startColumn }}
+ </NButton>
+ </div>
+ <div v-if="advice.content" class="col-start-2">
+ {{ advice.content }}
+ </div>
+ <div v-if="advice.detail" class="col-start-2">
+ {{ advice.detail }}
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { CircleAlertIcon } from "lucide-vue-next";
+import { NButton } from "naive-ui";
+import { computed } from "vue";
+import { positionWithOffset } from "@/components/MonacoEditor/utils";
+import type { SQLEditorQueryParams } from "@/types";
+import { Advice_Status, type Advice } from "@/types/proto/v1/sql_service";
+import { useSQLEditorContext } from "@/views/sql-editor/context";
+
+const props = defineProps<{
+ advice: Advice;
+ executeParams?: SQLEditorQueryParams;
+}>();
+const { events: editorEvents } = useSQLEditorContext();
+
+const title = computed(() => {
+ const { code, title } = props.advice;
+ const parts = [title];
+ if (code) {
+ parts.unshift(`(${code})`);
+ }
+ return parts.join(" ");
+});
+
+const position = computed(() => {
+ const { advice, executeParams } = props;
+ const [startLine, startColumn] = positionWithOffset(
+ advice.startPosition?.line ?? advice.line,
+ advice.startPosition?.column ?? advice.column,
+ executeParams?.selection
+ );
+ const [endLine, endColumn] = positionWithOffset(
+ advice.endPosition?.line ?? advice.line,
+ advice.endPosition?.column ?? advice.column,
+ executeParams?.selection
+ );
+ return {
+ startLine,
+ startColumn,
+ endLine,
+ endColumn,
+ };
+});
+
+const doScroll = () => {
+ const { startLine, startColumn, endLine, endColumn } = position.value;
+ editorEvents.emit("set-editor-selection", {
+ start: { line: startLine, column: startColumn },
+ end: { line: endLine, column: endColumn },
+ });
+};
+</script>
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView/ErrorView.vue
similarity index 54%
rename from frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView.vue
rename to frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView/ErrorView.vue
index dd7f752d9e..ed8829ee30 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView/ErrorView.vue
@@ -3,17 +3,27 @@
class="text-md font-normal flex flex-col gap-2"
:class="[dark ? 'text-matrix-green-hover' : 'text-control-light']"
>
- <div class="flex items-center gap-3">
- <span>{{ error }}</span>
+ <template v-if="resultSet && resultSet.advices.length > 0">
+ <AdviceItem
+ v-for="(advice, i) in resultSet.advices"
+ :key="i"
+ :advice="advice"
+ :execute-params="executeParams"
+ />
+ </template>
+ <template v-else>
+ <div class="flex items-start gap-2">
+ <div class="shrink-0 flex items-center h-6">
+ <CircleAlertIcon class="w-6 h-6 text-error" />
+ </div>
+ <span>{{ error }}</span>
+ </div>
+ </template>
+ <div>
<slot name="suffix" />
</div>
- <div v-if="viewMode === 'RICH'">
- <NButton
- v-if="showRunAnywayButton"
- size="small"
- type="primary"
- @click="runAnyway"
- >
+ <div v-if="showRunAnywayButton">
+ <NButton size="small" type="primary" @click="runAnyway">
{{ $t("sql-editor.run-anyway") }}
</NButton>
</div>
@@ -21,13 +31,16 @@
</template>
<script lang="ts" setup>
+import { CircleAlertIcon } from "lucide-vue-next";
import { NButton } from "naive-ui";
+import { Status } from "nice-grpc-common";
import { computed } from "vue";
import { useExecuteSQL } from "@/composables/useExecuteSQL";
import { useAppFeature } from "@/store";
import type { SQLEditorQueryParams, SQLResultSetV1 } from "@/types";
import { Advice_Status } from "@/types/proto/v1/sql_service";
-import { useSQLResultViewContext } from "./context";
+import { useSQLResultViewContext } from "../context";
+import AdviceItem from "./AdviceItem.vue";
const props = defineProps<{
error: string | undefined;
@@ -39,17 +52,13 @@ const sqlCheckStyle = useAppFeature("bb.feature.sql-editor.sql-check-style");
const { dark } = useSQLResultViewContext();
const { execute } = useExecuteSQL();
-const viewMode = computed((): "SIMPLE" | "RICH" => {
- if (sqlCheckStyle.value === "PREFLIGHT") {
- if (!props.executeParams?.skipCheck) {
- return "RICH";
- }
- }
- return "SIMPLE";
-});
const showRunAnywayButton = computed(() => {
- const { resultSet } = props;
+ const { executeParams, resultSet } = props;
if (!resultSet) return false;
+ if (!executeParams) return false;
+ if (sqlCheckStyle.value !== "PREFLIGHT") return false;
+ if (resultSet.status === Status.PERMISSION_DENIED) return false;
+ if (resultSet.error.includes("resource not found")) return false;
if (
resultSet.advices.some((advice) => advice.status === Advice_Status.ERROR)
) {
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView/index.ts b/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView/index.ts
new file mode 100644
index 0000000000..56cde5ad7e
--- /dev/null
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView/index.ts
@@ -0,0 +1,3 @@
+import ErrorView from "./ErrorView.vue";
+
+export default ErrorView;
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
index 1590ae35c5..dc5f373478 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
@@ -120,7 +120,7 @@ import type { QueryResult } from "@/types/proto/v1/sql_service";
import { hasWorkspacePermissionV2 } from "@/utils";
import DetailPanel from "./DetailPanel.vue";
import EmptyView from "./EmptyView.vue";
-import ErrorView from "./ErrorView.vue";
+import ErrorView from "./ErrorView";
import RequestQueryButton from "./RequestQueryButton.vue";
import SingleResultViewV1 from "./SingleResultViewV1.vue";
import type { SQLResultViewContext } from "./context";
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
index 5e8650d1e2..72525b8f82 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
@@ -226,7 +226,7 @@ import {
import DataBlock from "./DataBlock.vue";
import DataTable from "./DataTable";
import EmptyView from "./EmptyView.vue";
-import ErrorView from "./ErrorView.vue";
+import ErrorView from "./ErrorView";
import { useSQLResultViewContext } from "./context";
type LocalState = {
diff --git a/frontend/src/views/sql-editor/EditorPanel/StandardPanel/SQLEditor.vue b/frontend/src/views/sql-editor/EditorPanel/StandardPanel/SQLEditor.vue
index adad0c986d..a819390e30 100644
--- a/frontend/src/views/sql-editor/EditorPanel/StandardPanel/SQLEditor.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/StandardPanel/SQLEditor.vue
@@ -37,6 +37,7 @@ import MonacoEditor from "@/components/MonacoEditor/MonacoEditor.vue";
import {
extensionNameOfLanguage,
formatEditorContent,
+ positionWithOffset,
} from "@/components/MonacoEditor/utils";
import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
import { useExecuteSQL } from "@/composables/useExecuteSQL";
@@ -62,6 +63,10 @@ const uiStateStore = useUIStateStore();
const { events: editorEvents } = useSQLEditorContext();
const { currentTab, isSwitchingTab } = storeToRefs(tabStore);
const pendingFormatContentCommand = ref(false);
+const pendingSetSelectionCommand = ref<{
+ start: { line: number; column: number };
+ end?: { line: number; column: number };
+}>();
const { events: executeSQLEvents } = useExecuteSQL();
const content = computed(() => currentTab.value?.statement ?? "");
@@ -99,10 +104,6 @@ const handleUpdateStatement = (value: string) => {
if (value === tab.statement) {
return;
}
- // Clear old advices when the statement is changed.
- tab.queryContext?.results.forEach((result) => {
- result.advices = [];
- });
tabStore.updateCurrentTab({
statement: value,
status: "DIRTY",
@@ -189,34 +190,49 @@ const handleEditorReady = (
},
{ immediate: true }
);
+
+ watch(
+ pendingSetSelectionCommand,
+ (range) => {
+ if (range) {
+ const start = range.start;
+ const end = range.end ?? start;
+ editor.setSelection({
+ startLineNumber: start.line,
+ startColumn: start.column,
+ endLineNumber: end.line,
+ endColumn: end.column,
+ });
+ editor.revealLineNearTop(start.line);
+ editor.focus();
+ nextTick(() => {
+ pendingSetSelectionCommand.value = undefined;
+ });
+ }
+ },
+ { immediate: true }
+ );
};
const updateAdvices = (
tab: SQLEditorTab,
params: SQLEditorQueryParams,
advices: Advice[]
) => {
- const withOffset = (advice: Advice) => {
- let line = advice.line;
- let column = advice.column + 1;
- const { selection } = params;
- if (!selection) {
- return { line, column };
- }
- if (
- selection.endLineNumber > selection.startLineNumber ||
- selection.endColumn > selection.startColumn
- ) {
- if (line === 1) {
- column += selection.startColumn - 1;
- }
- line += selection.startLineNumber - 1;
- }
- return { line, column };
- };
tab.editorState.advices = advices.map<AdviceOption>((advice) => {
- const { line, column } = withOffset(advice);
+ const [startLine, startColumn] = positionWithOffset(
+ advice.startPosition?.line ?? advice.line,
+ advice.startPosition?.column ?? advice.column,
+ params.selection
+ );
+ const [endLine, endColumn] = positionWithOffset(
+ advice.endPosition?.line ?? advice.startPosition?.line ?? advice.line,
+ advice.endPosition?.column ??
+ advice.startPosition?.column ??
+ advice.column,
+ params.selection
+ );
const code = advice.code;
- const source = [`L${line}:C${column - 1}`];
+ const source = [`L${startLine}:C${startColumn}`];
if (code > 0) {
source.unshift(`(${code})`);
}
@@ -227,10 +243,10 @@ const updateAdvices = (
severity: advice.status === Advice_Status.ERROR ? "ERROR" : "WARNING",
message: advice.content,
source: source.join(" "),
- startLineNumber: line,
- endLineNumber: line,
- startColumn: column,
- endColumn: column,
+ startLineNumber: startLine,
+ endLineNumber: endLine,
+ startColumn: startColumn,
+ endColumn: endColumn,
};
});
};
@@ -238,6 +254,9 @@ const updateAdvices = (
useEmitteryEventListener(editorEvents, "format-content", () => {
pendingFormatContentCommand.value = true;
});
+useEmitteryEventListener(editorEvents, "set-editor-selection", (range) => {
+ pendingSetSelectionCommand.value = range;
+});
useEmitteryEventListener(
executeSQLEvents,
diff --git a/frontend/src/views/sql-editor/context.ts b/frontend/src/views/sql-editor/context.ts
index 5865af6561..3febcb648a 100644
--- a/frontend/src/views/sql-editor/context.ts
+++ b/frontend/src/views/sql-editor/context.ts
@@ -25,6 +25,10 @@ type SQLEditorEvents = Emittery<{
"project-context-ready": {
project: string;
};
+ "set-editor-selection": {
+ start: { line: number; column: number };
+ end?: { line: number; column: number };
+ };
}>;
export type SQLEditorContext = {