Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(rollout): show the engine's error on a failed task run (#21256)
Vincent Huang4b6cd2cfca20
diff --git a/backend/plugin/db/bigquery/bigquery.go b/backend/plugin/db/bigquery/bigquery.goindex c771340c9c..94f02c1a18 100644--- a/backend/plugin/db/bigquery/bigquery.go+++ b/backend/plugin/db/bigquery/bigquery.go@@ -102,21 +102,51 @@ func (*Driver) GetDB() *sql.DB {}// Execute executes a SQL statement.-func (d *Driver) Execute(ctx context.Context, statement string, _ db.ExecuteOptions) (int64, error) {+func (d *Driver) Execute(ctx context.Context, statement string, opts db.ExecuteOptions) (int64, error) {q := d.client.Query(statement)q.DefaultDatasetID = d.databaseName++ // BigQuery submits the whole sheet as one query job, so the task run log+ // carries one command spanning the entire statement, as snowflake does.+ // Without these the log holds only the surrounding sync entries and the+ // engine's error reaches no reader.+ opts.LogCommandExecute(&storepb.Range{Start: 0, End: int32(len(statement))}, statement)+job, err := q.Run(ctx)if err != nil {+ opts.LogCommandResponse(0, nil, err.Error())return 0, err}status, err := job.Wait(ctx)if err != nil {+ opts.LogCommandResponse(0, nil, err.Error())return 0, err}if err := status.Err(); err != nil {+ opts.LogCommandResponse(0, nil, err.Error())return 0, err}- return 0, nil++ // NumDMLAffectedRows is 0 for DDL and for a multi-statement script, whose+ // parent job reports statementType SCRIPT and carries no row count.+ var affectedRows int64+ if stats, ok := statisticsOf(status); ok {+ affectedRows = stats.NumDMLAffectedRows+ }+ opts.LogCommandResponse(affectedRows, nil, "")+ return affectedRows, nil+}++// statisticsOf returns the query statistics of a finished job.+// JobStatus.Statistics is nil when the jobs.get response carried no statistics+// block (Job.setStatistics returns early on that), so the Details assertion+// alone dereferences nil.+func statisticsOf(status *bigquery.JobStatus) (*bigquery.QueryStatistics, bool) {+ if status.Statistics == nil {+ return nil, false+ }+ stats, ok := status.Statistics.Details.(*bigquery.QueryStatistics)+ return stats, ok}// QueryConn queries a SQL statement in a given connection.@@ -200,12 +230,11 @@ func (d *Driver) QueryConn(ctx context.Context, _ *sql.Conn, statement string, qif err := status.Err(); err != nil {return nil, err}- switch r := status.Statistics.Details.(type) {- case *bigquery.QueryStatistics:- return util.BuildAffectedRowsResult(r.NumDMLAffectedRows, nil), nil- default:+ stats, ok := statisticsOf(status)+ if !ok {return nil, errors.New("invalid status statistics detail type")}+ return util.BuildAffectedRowsResult(stats.NumDMLAffectedRows, nil), nil}()stop := falseif err != nil {@@ -282,7 +311,7 @@ func (d *Driver) dryRunQuery(ctx context.Context, statement string, queryContextLatency: durationpb.New(time.Since(startTime)),}- if stats, ok := status.Statistics.Details.(*bigquery.QueryStatistics); ok {+ if stats, ok := statisticsOf(status); ok {bytesProcessed := stats.TotalBytesProcessed// Format output similar to bq CLIdiff --git a/frontend/src/routes/project/plan-detail/components/deploy/DeployLatestTaskRunInfo.tsx b/frontend/src/routes/project/plan-detail/components/deploy/DeployLatestTaskRunInfo.tsxindex 5e079cfb5f..22b020b0e4 100644--- a/frontend/src/routes/project/plan-detail/components/deploy/DeployLatestTaskRunInfo.tsx+++ b/frontend/src/routes/project/plan-detail/components/deploy/DeployLatestTaskRunInfo.tsx@@ -14,6 +14,7 @@ import type { TaskRun } from "@/types/proto-es/v1/rollout_service_pb";import { TaskRun_Status } from "@/types/proto-es/v1/rollout_service_pb";import { stringifyTaskRunStatus } from "@/utils/v1/issue/rollout";import { PlanDetailTaskRunSession } from "../PlanDetailTaskRunSession";+import { TaskRunErrorAlert } from "./TaskRunErrorAlert";const STATUS_LABEL_CLASS: Partial<Record<TaskRun_Status, string>> = {[TaskRun_Status.RUNNING]: "text-info",@@ -102,6 +103,8 @@ export function DeployLatestTaskRunInfo({)}</div>+ <TaskRunErrorAlert taskRun={taskRun} />+{/* Status is part of the key on purpose: a status flip (RUNNING→DONE)remounts the viewer for a fresh disclosure state on the new phase.The remount paints fully formed — useTaskRunLogData seeds from itsdiff --git a/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskRunHistorySheet.tsx b/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskRunHistorySheet.tsxindex 3d467ed135..b5e906d8f2 100644--- a/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskRunHistorySheet.tsx+++ b/frontend/src/routes/project/plan-detail/components/deploy/DeployTaskRunHistorySheet.tsx@@ -20,6 +20,7 @@ import {} from "@/lib/taskRun";import { getTimeForPbTimestampProtoEs } from "@/types";import type { TaskRun } from "@/types/proto-es/v1/rollout_service_pb";+import { TaskRunErrorAlert } from "./TaskRunErrorAlert";// With this many runs or more, only the newest run starts expanded; older// runs collapse to header rows. Keeps the sheet scannable and avoids fetching@@ -154,7 +155,8 @@ function TaskRunHistoryItem({</span></button>{isExpanded && (- <div className="border-t p-3">+ <div className="flex flex-col gap-2 border-t p-3">+ <TaskRunErrorAlert taskRun={taskRun} />{/* Status is part of the key (as in the latest-run panel): aRUNNING -> DONE flip remounts the viewer so useTaskRunLogData'sunmount cleanup invalidates the in-flight RUNNING log request,diff --git a/frontend/src/routes/project/plan-detail/components/deploy/TaskRunErrorAlert.tsx b/frontend/src/routes/project/plan-detail/components/deploy/TaskRunErrorAlert.tsxnew file mode 100644index 0000000000..763cde2fb4--- /dev/null+++ b/frontend/src/routes/project/plan-detail/components/deploy/TaskRunErrorAlert.tsx@@ -0,0 +1,32 @@+import { useTranslation } from "react-i18next";+import { Alert } from "@/components/ui/alert";+import type { TaskRun } from "@/types/proto-es/v1/rollout_service_pb";+import { TaskRun_Status } from "@/types/proto-es/v1/rollout_service_pb";++// The engine's error for a failed run. The task run log below it cannot be+// relied on to carry the cause: several drivers (cassandra, databricks,+// elasticsearch, hive, redis, spanner and starrocks among them) never write a+// command-response entry, so their logs hold only the surrounding sync steps+// and a failure reads as "Database Sync Completed" with no cause anywhere.+//+// The log loads asynchronously, so gating this on the log's contents would+// flip the alert after first paint.+export function TaskRunErrorAlert({ taskRun }: Readonly<{ taskRun: TaskRun }>) {+ const { t } = useTranslation();++ if (taskRun.status !== TaskRun_Status.FAILED || !taskRun.detail) {+ return null;+ }++ return (+ <Alert+ variant="error"+ title={t("common.error")}+ description={+ <span className="whitespace-pre-wrap break-words font-mono text-xs">+ {taskRun.detail}+ </span>+ }+ />+ );+}