spindle: expose knot-side workflow errors as a fake step to the UI #424

merged
opened by winter.bsky.social targeting master from winter.bsky.social/core: push-luoyqwkpromz
Changed files
+31
spindle
+31
spindle/stream.go
··· 6 6 "fmt" 7 7 "io" 8 8 "net/http" 9 + "os" 9 10 "strconv" 10 11 "time" 11 12 ··· 145 146 146 147 filePath := engine.LogFilePath(s.cfg.Server.LogDir, wid) 147 148 149 + if status.Status == models.StatusKindFailed.String() && status.Error != nil { 150 + if _, err := os.Stat(filePath); os.IsNotExist(err) { 151 + msgs := []models.LogLine{ 152 + { 153 + Kind: models.LogKindControl, 154 + Content: "", 155 + StepId: 0, 156 + StepKind: models.StepKindUser, 157 + }, 158 + { 159 + Kind: models.LogKindData, 160 + Content: *status.Error, 161 + }, 162 + } 163 + 164 + for _, msg := range msgs { 165 + b, err := json.Marshal(msg) 166 + if err != nil { 167 + return err 168 + } 169 + 170 + if err := conn.WriteMessage(websocket.TextMessage, b); err != nil { 171 + return fmt.Errorf("failed to write to websocket: %w", err) 172 + } 173 + } 174 + 175 + return nil 176 + } 177 + } 178 + 148 179 config := tail.Config{ 149 180 Follow: !isFinished, 150 181 ReOpen: !isFinished,