Skip to content

Fix: Improve error messages for cancelled/failed jobs (fixes #131)#132

Merged
wkoszek merged 1 commit intomainfrom
issue/131
Nov 25, 2025
Merged

Fix: Improve error messages for cancelled/failed jobs (fixes #131)#132
wkoszek merged 1 commit intomainfrom
issue/131

Conversation

@wkoszek
Copy link
Copy Markdown
Contributor

@wkoszek wkoszek commented Nov 25, 2025

Summary

Parse server response body to extract actual error messages instead of showing generic HTTP status codes. Provides clearer feedback when jobs are cancelled, failed, or otherwise unavailable.

Changes

  • Add JSON error response parsing in cat command
  • Add JSON error response parsing in submit command
  • Show actual error message from server when available
  • Fall back to showing response body if JSON parsing fails
  • Import encoding/json and io packages

Example

Before

$ bsubio cat <cancelled-job-id>
Error: failed to get job output: HTTP 400

After

$ bsubio cat <cancelled-job-id>
Error: failed to get job output: job was cancelled

Implementation

When receiving non-200 status from GetJobOutput:

  1. Read response body
  2. Try to parse as JSON with {"error": "message"} format
  3. If successful, show the error message
  4. Otherwise, show HTTP status + raw response body

Fixes #131

Parse server response body to extract actual error messages instead
of showing generic HTTP status codes. This provides clearer feedback
when jobs are cancelled, failed, or otherwise unavailable.

Changes:
- Add JSON error response parsing in cat command
- Add JSON error response parsing in submit command
- Show actual error message from server when available
- Fall back to showing response body if JSON parsing fails
- Import encoding/json and io packages

Example before:
  Error: failed to get job output: HTTP 400

Example after:
  Error: failed to get job output: job was cancelled
@claude
Copy link
Copy Markdown

claude bot commented Nov 25, 2025

Code Review

Bug: Response body read after close in submit.go

Line 223: _ = outputResp.Body.Close() is called immediately after reading the body at line 222, but then the same body is read again in lines 231-235 for JSON unmarshaling. The body was already consumed and closed, making the second read fail.

Fix: move Close() to a defer after the status check:

if outputResp.StatusCode != 200 {
    defer outputResp.Body.Close()
    body, err := io.ReadAll(outputResp.Body)
    // ... rest of error handling
}

Duplication

Error parsing logic is duplicated in cat.go:103-115 and submit.go:221-236. Extract to a helper function to reduce repetition and ensure consistent error handling across commands.

@wkoszek wkoszek merged commit 15e7dc8 into main Nov 25, 2025
3 checks passed
@wkoszek wkoszek deleted the issue/131 branch November 25, 2025 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error message when getting output from cancelled/failed jobs

1 participant