From 3217bbfe4d36a116955b379b102be158141151cc Mon Sep 17 00:00:00 2001 From: Justin Harms Date: Mon, 24 Nov 2025 21:49:17 -0600 Subject: [PATCH] Refactor error handling and improve code formatting in runners.go. Replace fmt.Errorf with errors.New for better error management. Clean up whitespace and enhance readability in various API response structures. --- internal/api/runners.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/api/runners.go b/internal/api/runners.go index b369718..242daa5 100644 --- a/internal/api/runners.go +++ b/internal/api/runners.go @@ -4,6 +4,7 @@ import ( "context" "database/sql" "encoding/json" + "errors" "fmt" "io" "log" @@ -295,10 +296,10 @@ func (s *Server) handleUpdateTaskStep(w http.ResponseWriter, r *http.Request) { if err == nil { // Broadcast step update to frontend s.broadcastTaskUpdate(jobID, taskID, "step_update", map[string]interface{}{ - "step_id": stepID, - "step_name": req.StepName, - "status": req.Status, - "duration_ms": req.DurationMs, + "step_id": stepID, + "step_name": req.StepName, + "status": req.Status, + "duration_ms": req.DurationMs, "error_message": req.ErrorMessage, }) } @@ -338,7 +339,7 @@ func (s *Server) handleDownloadJobContext(w http.ResponseWriter, r *http.Request // Set appropriate headers for tar file w.Header().Set("Content-Type", "application/x-tar") w.Header().Set("Content-Disposition", "attachment; filename=context.tar") - + // Stream the file to the response io.Copy(w, file) } @@ -1153,8 +1154,8 @@ func (s *Server) updateJobStatusFromTasks(jobID int64) { } // Broadcast job update via WebSocket s.broadcastJobUpdate(jobID, "job_update", map[string]interface{}{ - "status": jobStatus, - "progress": progress, + "status": jobStatus, + "progress": progress, "completed_at": now, }) } @@ -1184,7 +1185,7 @@ func (s *Server) updateJobStatusFromTasks(jobID int64) { // Broadcast that a new task was added log.Printf("Broadcasting task_added for job %d: video generation task %d", jobID, videoTaskID) s.broadcastTaskUpdate(jobID, videoTaskID, "task_added", map[string]interface{}{ - "task_id": videoTaskID, + "task_id": videoTaskID, "task_type": types.TaskTypeVideoGeneration, }) // Update job status to ensure it's marked as running (has pending video task) @@ -1790,7 +1791,7 @@ func (s *Server) assignTaskToRunner(runnerID int64, taskID int64) error { types.TaskStatusPending, taskID, ) s.logTaskEvent(taskID, nil, types.LogLevelError, errMsg, "") - return fmt.Errorf(errMsg) + return errors.New(errMsg) } // Note: Task is already assigned in database by the atomic update in distributeTasksToRunners