Skip to content

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

feat: display position information for execution error (#9522)

rebeliced0c64783de99
diff --git a/backend/api/v1/rollout_service_converter.go b/backend/api/v1/rollout_service_converter.go
index de5a44ab9d..0c61f37649 100644
--- a/backend/api/v1/rollout_service_converter.go
+++ b/backend/api/v1/rollout_service_converter.go
@@ -494,6 +494,19 @@ func convertToTaskRun(stateCfg *state.State, taskRun *store.TaskRunMessage) *v1p
}
}
+ if taskRun.Status == api.TaskRunFailed && taskRun.ResultProto.StartPosition != nil && taskRun.ResultProto.EndPosition != nil {
+ t.ExecutionDetail = &v1pb.TaskRun_ExecutionDetail{
+ CommandStartPosition: &v1pb.TaskRun_ExecutionDetail_Position{
+ Line: taskRun.ResultProto.StartPosition.Line,
+ Column: taskRun.ResultProto.StartPosition.Column,
+ },
+ CommandEndPosition: &v1pb.TaskRun_ExecutionDetail_Position{
+ Line: taskRun.ResultProto.EndPosition.Line,
+ Column: taskRun.ResultProto.EndPosition.Column,
+ },
+ }
+ }
+
return t
}
diff --git a/backend/plugin/db/driver.go b/backend/plugin/db/driver.go
index 04bc1b220a..162eab80b7 100644
--- a/backend/plugin/db/driver.go
+++ b/backend/plugin/db/driver.go
@@ -488,3 +488,14 @@ type ExecuteOptions struct {
ChunkedSubmission bool
UpdateExecutionStatus func(*v1pb.TaskRun_ExecutionDetail)
}
+
+// ErrorWithPosition is the error with the position information.
+type ErrorWithPosition struct {
+ Err error
+ Start *storepb.TaskRunResult_Position
+ End *storepb.TaskRunResult_Position
+}
+
+func (e *ErrorWithPosition) Error() string {
+ return e.Err.Error()
+}
diff --git a/backend/plugin/db/mysql/mysql.go b/backend/plugin/db/mysql/mysql.go
index aa265aaf56..cdb3795e22 100644
--- a/backend/plugin/db/mysql/mysql.go
+++ b/backend/plugin/db/mysql/mysql.go
@@ -243,7 +243,17 @@ func (driver *Driver) Execute(ctx context.Context, statement string, _ bool, opt
sqlResult, err := tx.ExecContext(ctx, chunkText)
if err != nil {
- return 0, errors.Wrapf(err, "failed to execute context in a transaction")
+ return 0, &db.ErrorWithPosition{
+ Err: errors.Wrapf(err, "failed to execute context in a transaction"),
+ Start: &storepb.TaskRunResult_Position{
+ // TODO(rebelice): should find the first non-comment and blank line and column.
+ Line: int32(chunk[0].BaseLine),
+ },
+ End: &storepb.TaskRunResult_Position{
+ // TODO(rebelice): should find the first non-comment and blank line and column.
+ Line: int32(chunk[len(chunk)-1].BaseLine),
+ },
+ }
}
rowsAffected, err := sqlResult.RowsAffected()
if err != nil {
diff --git a/backend/runner/taskrun/schedulerv2.go b/backend/runner/taskrun/schedulerv2.go
index 8468df002a..3134555528 100644
--- a/backend/runner/taskrun/schedulerv2.go
+++ b/backend/runner/taskrun/schedulerv2.go
@@ -16,6 +16,7 @@ import (
"github.com/bytebase/bytebase/backend/component/activity"
"github.com/bytebase/bytebase/backend/component/state"
api "github.com/bytebase/bytebase/backend/legacyapi"
+ "github.com/bytebase/bytebase/backend/plugin/db"
"github.com/bytebase/bytebase/backend/store"
"github.com/bytebase/bytebase/backend/utils"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -424,11 +425,19 @@ func (s *SchedulerV2) runTaskRunOnce(ctx context.Context, taskRun *store.TaskRun
log.BBError(err),
)
- resultBytes, marshalErr := protojson.Marshal(&storepb.TaskRunResult{
+ taskRunResult := &storepb.TaskRunResult{
Detail: err.Error(),
ChangeHistory: "",
Version: "",
- })
+ }
+
+ var errWithPosition *db.ErrorWithPosition
+ if errors.As(err, &errWithPosition) {
+ taskRunResult.StartPosition = errWithPosition.Start
+ taskRunResult.EndPosition = errWithPosition.End
+ }
+
+ resultBytes, marshalErr := protojson.Marshal(taskRunResult)
if marshalErr != nil {
slog.Error("Failed to marshal task run result",
slog.Int("task_id", task.ID),
diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunComment.vue b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunComment.vue
index 79b911062e..cb79fbf78a 100644
--- a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunComment.vue
+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunComment.vue
@@ -82,6 +82,17 @@ const comment = computed(() => {
) {
return t("task-run.status.dumping-schema-after-executing-sql");
}
+ } else if (taskRun.status === TaskRun_Status.FAILED) {
+ if (
+ taskRun.executionDetail?.commandStartPosition &&
+ taskRun.executionDetail?.commandEndPosition
+ ) {
+ return t("task-run.status.failed-sql-detail", {
+ start: taskRun.executionDetail.commandStartPosition?.line ?? 0 + 1,
+ end: taskRun.executionDetail.commandEndPosition?.line ?? 0 + 1,
+ message: taskRun.detail,
+ });
+ }
}
return taskRun.detail;
});
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index fee5d3baba..d13a976534 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -410,7 +410,8 @@
"dumping-schema-before-executing-sql": "Preparing to execute, dumping schema.",
"executing-sql": "Executing SQL.",
"executing-sql-detail": "Executing SQL {current} of {total}, from line {start} to line {end}.",
- "dumping-schema-after-executing-sql": "SQL execution completed, dumping schema."
+ "dumping-schema-after-executing-sql": "SQL execution completed, dumping schema.",
+ "failed-sql-detail": "Execution failed from line {start} to line {end}: {message}."
}
},
"banner": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index e43d2628d6..b626e5d4b1 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -410,7 +410,8 @@
"dumping-schema-before-executing-sql": "Listo para ejecutar, exportando esquema.",
"executing-sql": "Ejecutando SQL.",
"dumping-schema-after-executing-sql": "Ejecución SQL completada, exportando esquema ahora.",
- "executing-sql-detail": "Ejecutando SQL {current} de {total}, desde la línea {start} hasta la línea {end}."
+ "executing-sql-detail": "Ejecutando SQL {current} de {total}, desde la línea {start} hasta la línea {end}.",
+ "failed-sql-detail": "La ejecución falló desde la línea {start} hasta la línea {end}: {message}."
}
},
"banner": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index e840636b57..b0289ffbe2 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -408,7 +408,8 @@
"dumping-schema-before-executing-sql": "准备执行,正在导出 schema。",
"executing-sql": "正在执行 SQL。",
"executing-sql-detail": "正在执行 SQL {current} / {total}。 SQL 语句位于 {start} 行到 {end} 行。",
- "dumping-schema-after-executing-sql": "SQL 执行完毕,正在导出 schema。"
+ "dumping-schema-after-executing-sql": "SQL 执行完毕,正在导出 schema。",
+ "failed-sql-detail": "从 {start} 行到 {end} 行执行失败:{message}。"
}
},
"banner": {