From e8ea91268a1b5f2359c93713d7f6462809d3e6f8 Mon Sep 17 00:00:00 2001 From: Daniel Samson <12231216+daniel-samson@users.noreply.github.com> Date: Wed, 21 Jan 2026 22:15:07 +0000 Subject: [PATCH] fix(jobs): write startup errors to stderr.log When a job fails to start (e.g., command not found), the error is now written to stderr.log so it appears in `barn describe --logs` output. Previously, the log files were empty for jobs that failed before the process could start, making it hard to diagnose the issue. Co-Authored-By: Claude Opus 4.5 --- .../java/com/samsonmedia/barn/execution/JobRunner.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/samsonmedia/barn/execution/JobRunner.java b/src/main/java/com/samsonmedia/barn/execution/JobRunner.java index d6a4bee..cf7049d 100644 --- a/src/main/java/com/samsonmedia/barn/execution/JobRunner.java +++ b/src/main/java/com/samsonmedia/barn/execution/JobRunner.java @@ -1,6 +1,7 @@ package com.samsonmedia.barn.execution; import java.io.IOException; +import java.nio.file.Files; import java.time.Duration; import java.time.Instant; import java.util.Objects; @@ -164,6 +165,15 @@ public class JobRunner { } catch (IOException e) { LOG.error("Failed to start job {}: {}", job.id(), e.getMessage(), e); + // Write error to stderr.log so it appears in --logs output + try { + var stderrFile = dirs.getJobLogsDir(job.id()).resolve(STDERR_LOG); + Files.createDirectories(stderrFile.getParent()); + Files.writeString(stderrFile, "Failed to start process: " + e.getMessage() + "\n"); + } catch (IOException writeError) { + LOG.warn("Failed to write error to stderr.log for job {}: {}", job.id(), writeError.getMessage()); + } + if (!completed.get()) { try { repository.markFailed(job.id(), "start_failed", e.getMessage());