ISSUE DESCRIPTION Fail on HTTP Status 204 (No Content) Hello, I'm using Synadia Cloud…
- User
ISSUE DESCRIPTION
Fail on HTTP Status 204 (No Content) Hello,
I'm using Synadia Cloud which has a
DELETEAPI that returns a response with no body.$ restish synadia delete-nats-user --help Deletes a NATS user from an account ## Argument Schema: { user-id: (string) } ## Responses 204/400/401/403/404 Response has no bodyIn this case, it's expected to have an empty body. Nevertheless,
restishfails with the error:ERROR: Parse response error ERROR: Caught error: EOFHere is the full log:
DEBUG: API loading took 6.245709ms DEBUG: Configuration: [REDACTED] DEBUG: Adding TLS configuration DEBUG: Making request: DELETE /api/core/beta/nats-users/[REDACTED] HTTP/1.1 Host: cloud.synadia.com Accept: application/msgpack;q=0.8,application/cbor;q=0.9,application/ion;q=0.6,application/json;q=0.5,application/yaml;q=0.5,text/*;q=0.2,*/* Accept-Encoding: deflate, gzip, br Authorization: [REDACTED] User-Agent: restish-0.20.0 DEBUG: Got response from server in 426.428041ms: HTTP/2.0 204 No Content Content-Encoding: gzip Date: Mon, 26 May 2025 19:48:15 GMT Set-Cookie: [REDACTED] Strict-Transport-Security: max-age=15768000 ; includeSubDomains Vary: Accept-Encoding X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN DEBUG: Decoding response from gzip ERROR: Parse response error ERROR: Caught error: EOF DEBUG: goroutine 1 [running]: runtime/debug.Stack() /opt/hostedtoolcache/go/1.18.10/x64/src/runtime/debug/stack.go:24 +0x68 github.com/danielgtaylor/restish/cli.Run.func1() /home/runner/work/restish/restish/cli/cli.go:849 +0x68 panic({0x1051c4f40, 0x140001900f0}) /opt/hostedtoolcache/go/1.18.10/x64/src/runtime/panic.go:838 +0x204 github.com/danielgtaylor/restish/cli.MakeRequestAndFormat(0x1052d4830?) /home/runner/work/restish/restish/cli/request.go:568 +0x118 github.com/danielgtaylor/restish/cli.Operation.command.func1(0x14000693800?, {0x1400061e8a0, 0x1, 0x2}) /home/runner/work/restish/restish/cli/operation.go:142 +0x814 github.com/spf13/cobra.(*Command).execute(0x14000693800, {0x1400061e880, 0x2, 0x2}) /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:920 +0x5dc github.com/spf13/cobra.(*Command).ExecuteC(0x1400034e600) /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:1044 +0x35c github.com/spf13/cobra.(*Command).Execute(...) /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:968 github.com/danielgtaylor/restish/cli.Run() /home/runner/work/restish/restish/cli/cli.go:857 +0x9a8 main.main() /home/runner/work/restish/restish/main.go:40 +0x370Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /restish, current file: none) bash-$
Assistant
Now let's check the same issue applies to
rawResponseBodyBytesanddecompressedResponseBodyin http.go, which are used for raw/streaming outputs.Assistant
Good,
readCloserembedsio.Readerandio.Closerdirectly (fields namedReaderandCloservia embedding), so my struct literal using field namesReader:andCloser:should work since embedded fields can be referenced by type name. Let's build.Assistant
Build succeeds. Let's write a quick reproduction script to verify the fix.
Assistant
The fix works. Now let's test the raw body path and streaming path fixes as well, then run the full test suite.
Assistant
Good, clean. Now let's run the relevant test suites.
Assistant
Now let's rebuild and rerun tests.
Assistant
All tests pass now. Let's run the entire test suite to be thorough.
Assistant
All tests pass. Now let's write a comprehensive reproduction test simulating the full CLI flow (like the actual issue - a real command through
restish get/delete) to validate the fix end-to-end, including the raw print mode too.Assistant
The fix resolves the issue end-to-end. Let's remove the temporary test file and run the full suite once more to confirm everything is clean.
Assistant
All tests pass. Let's review the final diff.
Assistant
This is a clean, minimal fix. Let me also double check the
panicscenario mentioned in the original issue traceback isn't reproducible elsewhere, e.g. maybe there's also aMakeRequestAndFormattype function or similar panic-inducing code path in current codebase structure.Assistant
Let's verify the fix indeed resolves what would otherwise fail, by temporarily reverting and running the repro test.
Assistant
Confirmed: without the fix, it fails with
decompressing response: EOF, exactly matching the issue. Now restore the fix and verify it passes.Assistant
The fix resolves the exact error from the issue. Now let's clean up the temporary test file and run the full test suite one final time.
Assistant
All tests pass, the repository builds cleanly, and
go vetreports no issues.Assistant
Summary
Root cause: When a server responds with an empty body (e.g., HTTP 204 No Content) but still includes a
Content-Encoding: gzipheader, restish would immediately try to decompress the (empty) body usinggzip.NewReader(). Sincegzip.NewReadereagerly reads the gzip header from the stream, it fails withio.EOFon a truly empty reader — even though there's nothing wrong with the response. This surfaced asERROR: Parse response error/ERROR: Caught error: EOF(and, in the older code referenced by the issue, a panic).Fix: In both
internal/output/response.go(decodeBody, used for the main formatted response parsing path) andinternal/cli/http.go(rawResponseBodyBytes, used for raw body output), I now peek a single byte from the response body via abufio.Readerbefore invoking the content-encoding decompressor. If the peek returnsio.EOF(i.e., the body is genuinely empty), we short-circuit and treat it as an empty/nil body instead of attempting decompression — regardless of whatContent-Encodingheader is present. If the peek fails for any other reason, that real I/O error is still correctly propagated.I intentionally did not apply the same eager-peek approach to
decompressedResponseBody, which is used for streaming (SSE/NDJSON) responses — eagerly peeking there would consume/trigger read errors too early and break the existing "SSE stream error" test surfaces (TestSSEReadErrorFailsCommand), since streaming responses need lazy reads to correctly attribute errors to the stream-reading layer. This is fine because streaming content types wouldn't realistically be paired with 204 No Content responses that this issue is about.Verification:
- Reproduced the bug in isolation using a
httptestserver returning204+Content-Encoding: gzipwith no body, confirmedoutput.Normalizefailed withdecompressing response: EOFprior to the fix. - Confirmed a full CLI run (
restish delete <url>against that same 204 gzip-encoded empty-body server) failed the same way before the fix, and succeeds after. - Ran the complete existing test suite (
go build ./...,go vet ./...,go test ./...) — everything passes, including the SSE/streaming error-handling tests that could have been affected by a naive fix. - Removed all temporary reproduction files before finalizing; only the two source files listed above are modified.
Checklist
- Reproduced the reported error (
decompressing response: EOF/ equivalent to the originalCaught error: EOF) using a minimal HTTP 204 + gzip Content-Encoding scenario. - Confirmed the fix resolves the error — the same reproduction now completes successfully with no error.
- Considered edge cases: non-gzip encodings (deflate/brotli) with empty bodies (also fixed generally, since the check happens before any encoding-specific decompressor runs), genuine I/O read errors on peek (still correctly propagated, not silently swallowed), and streaming responses (deliberately left as lazy-read to avoid altering their error semantics/tests).
- Ran the full existing test suite (
go test ./...) and confirmed everything passes, including a test that initially broke due to an overly broad first attempt at the fix (I identified and corrected that regression before finalizing).
- Reproduced the bug in isolation using a
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →