From e27dcb054f4fe9891d88f82b536dc7d83e375a29 Mon Sep 17 00:00:00 2001 From: Winter Date: Fri, 8 Aug 2025 13:48:18 -0400 Subject: [PATCH] spindle: expose knot-side workflow errors as a fake step to the UI Change-Id: lkxtpznwlqvsyqtpkmxxvpxyvslmszoo Signed-off-by: Winter --- spindle/stream.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/spindle/stream.go b/spindle/stream.go index 6167487..3c06de8 100644 --- a/spindle/stream.go +++ b/spindle/stream.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "net/http" + "os" "strconv" "time" @@ -144,6 +145,36 @@ func (s *Spindle) streamLogsFromDisk(ctx context.Context, conn *websocket.Conn, filePath := models.LogFilePath(s.cfg.Server.LogDir, wid) + if status.Status == models.StatusKindFailed.String() && status.Error != nil { + if _, err := os.Stat(filePath); os.IsNotExist(err) { + msgs := []models.LogLine{ + { + Kind: models.LogKindControl, + Content: "", + StepId: 0, + StepKind: models.StepKindUser, + }, + { + Kind: models.LogKindData, + Content: *status.Error, + }, + } + + for _, msg := range msgs { + b, err := json.Marshal(msg) + if err != nil { + return err + } + + if err := conn.WriteMessage(websocket.TextMessage, b); err != nil { + return fmt.Errorf("failed to write to websocket: %w", err) + } + } + + return nil + } + } + config := tail.Config{ Follow: !isFinished, ReOpen: !isFinished, -- 2.43.0