Skip to content

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

chore: optimize the sql query error message (#14986)

ecmadao3d3377c745cc
diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.go
index 62eabe73c6..d0fbcd7338 100644
--- a/backend/api/v1/sql_service.go
+++ b/backend/api/v1/sql_service.go
@@ -225,8 +225,22 @@ func (s *SQLService) Query(ctx context.Context, request *v1pb.QueryRequest) (*v1
}
if queryErr != nil {
code := codes.Internal
- if status, ok := status.FromError(queryErr); ok && status.Code() != codes.OK && status.Code() != codes.Unknown {
- code = status.Code()
+ if errorStatus, ok := status.FromError(queryErr); ok {
+ if errorStatus.Code() != codes.OK && errorStatus.Code() != codes.Unknown {
+ code = errorStatus.Code()
+ }
+ } else if syntaxErr, ok := queryErr.(*base.SyntaxError); ok {
+ querySyntaxError, err := status.New(codes.InvalidArgument, queryErr.Error()).WithDetails(
+ &v1pb.PlanCheckRun_Result_SqlReviewReport{
+ Line: int32(syntaxErr.Line),
+ Column: int32(syntaxErr.Column),
+ Detail: syntaxErr.Message,
+ Code: int32(advisor.StatementSyntaxError),
+ },
+ )
+ if err == nil {
+ return nil, querySyntaxError.Err()
+ }
}
return nil, status.Error(code, queryErr.Error())
}
@@ -398,7 +412,7 @@ func queryRetry(
store.IgnoreDatabaseAndTableCaseSensitive(instance),
)
if err != nil {
- return nil, nil, time.Duration(0), status.Errorf(codes.Internal, "failed to get query span: %v", err.Error())
+ return nil, nil, time.Duration(0), err
}
// After replacing backup table with source, we can apply the original access check and mask sensitive data for backup table.
// If err != nil, this function will return the original spans.
@@ -459,7 +473,7 @@ func queryRetry(
store.IgnoreDatabaseAndTableCaseSensitive(instance),
)
if err != nil {
- return nil, nil, duration, status.Errorf(codes.Internal, "failed to get query span: %v", err.Error())
+ return nil, nil, time.Duration(0), err
}
// After replacing backup table with source, we can apply the original access check and mask sensitive data for backup table.
// If err != nil, this function will return the original spans.
@@ -1168,6 +1182,7 @@ func validateQueryRequest(instance *store.InstanceMessage, statement string) err
Line: int32(syntaxErr.Line),
Column: int32(syntaxErr.Column),
Detail: syntaxErr.Message,
+ Code: int32(advisor.StatementSyntaxError),
},
)
if err != nil {
diff --git a/frontend/src/store/modules/v1/sql.ts b/frontend/src/store/modules/v1/sql.ts
index a97d880ebd..283910b226 100644
--- a/frontend/src/store/modules/v1/sql.ts
+++ b/frontend/src/store/modules/v1/sql.ts
@@ -20,12 +20,11 @@ const getSqlReviewReports = (err: unknown): Advice[] => {
extra.value
);
advices.push(
- Advice.fromJSON({
+ Advice.fromPartial({
status: Advice_Status.ERROR,
code: sqlReviewReport.code,
- title: "",
+ title: "SQL Review Failed",
content: sqlReviewReport.detail,
- detail: sqlReviewReport.detail,
line: sqlReviewReport.line,
column: sqlReviewReport.column,
})
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView/AdviceItem.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView/AdviceItem.vue
index 5172dc0e98..a3d393d50f 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView/AdviceItem.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView/AdviceItem.vue
@@ -22,9 +22,6 @@
<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>