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 +0x370ADDITIONAL 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 using command. Additionally, you can use and to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call ) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. Assistant
Let me start by understanding the issue. The problem is that RESTish crashes with an "EOF" error when receiving an HTTP 204 No Content response. HTTP 204 responses have no body, and the code seems to panic when trying to parse an empty body.
Let me explore the repository structure first, then look at the relevant code mentioned in the stack trace (cli/request.go:568 and cli/operation.go:142).
Assistant
Let me look at the relevant files mentioned in the stack trace.
Assistant
The cli directory seems to be under cmd or somewhere else. Let me look at the structure.
Assistant
It's under
internal/cli. Let me look at the relevant files mentioned in the stack trace.Assistant
Let me look for the MakeRequestAndFormat function and the files mentioned in the stack trace
Assistant
Let me search for MakeRequestAndFormat.
Assistant
The function name might be slightly different. Let me look at different patterns.
Assistant
Let me search more broadly
Assistant
Let me look at the operation files.
Assistant
Let me search for "EOF" error and look at the HTTP handling code
Assistant
Let me look at the http.go file around the area that handles response body parsing.
Assistant
Let me read the http.go file.
Assistant
Let me look at the code around line 1400 and also find where the response body is decoded/parsed
Assistant
Let me look for the MakeRequest function and the response parsing logic
Assistant
Let me look at request_exec.go since it's the closest match for the stack trace.
Assistant
Let me search for where the response body is read and decoded
Assistant
Let me look at the response body reading code around line 661 and line 674.
Assistant
Let me search for "Parse response error" and also look at the code around where the body is parsed as JSON/YAML/etc.
Assistant
Let me search for related error strings more broadly.
Assistant
Let me search more broadly for where response body parsing happens.
Assistant
Let me look around line 322 where the decoding logic is mentioned.
Assistant
Let me look at the normalizeHTTPResponse function.
Assistant
Let me search for normalizeHTTPResponse across the whole codebase.
Assistant
Let me look at the normalizeHTTPResponse function in request_exec.go.
Assistant
Let me look at the output package where Normalize is defined.
Assistant
Let me search for the Normalize function in the output package.
Assistant
Let me look at the Normalize function in output/response.go
Assistant
Now I see the issue. For HTTP 204 No Content, there's no body. But the server includes
Content-Encoding: gzipfrom the actual response log. Let me look at the content registry's Decompress function.Assistant
Let me look at how default encodings are registered, and where the issue manifests
Assistant
Now I have a clear understanding of the problem. Let me look at the
decodeBodyfunction again and trace the exact error path.The issue is:
- HTTP 204 No Content has an empty body
- But the server sends
Content-Encoding: gzip decodeBodycallsreg.Decompress("gzip", resp.Body)which callsgzip.NewReader(r)gzip.NewReadertries to read gzip header from the empty body → getsio.EOF- This error propagates up causing the crash
Let me first create a reproduce script to confirm this:
Assistant
Let me set GOCACHE and try again.
Assistant
Let me fix the script.
Assistant
Confirmed:
gzip.NewReaderon an empty body returnsio.EOF. Now let me also check brotli and deflate for similarAssistant
Now I understand the issue fully. Let me implement the fix. The problem is in
decodeBodyininternal/output/response.go- whengzip.NewReaderis called on an empty body, it returnsio.EOF. Let me fix this:Assistant
I need to go back to the repository root.
Assistant
Now let me implement the fix. I'll modify the
decodeBodyfunction to handle the EOF error from decompression, which occurs when the body is empty (HTTP 204/304):Assistant
Let me use replace instead to make this change:
Assistant
Let me use the heredoc syntax:
Assistant
Good, the change looks correct. Now let me also check and fix the similar issue in
rawResponseBodyBytesin http.go:Assistant
Let me fix the same issue in
rawResponseBodyBytesin http.go:Assistant
Let me use the heredoc syntax:
Assistant
Let me look at the exact code around line 667:
Assistant
I see, the file uses tabs for indentation. Let me use the correct indentation:
Assistant
Let me view the file at line 667 directly:
Assistant
Let me use sed to make the edit in http.go:
Assistant
Let me try using a Python script to make the edit since the replace command is having trouble:
Assistant
Let me verify the edit was applied correctly:
Assistant
Both fixes look good. Let me also check the
decompressedResponseBodyfunction which has a similar pattern:Assistant
Let me fix
decompressedResponseBodytoo:Assistant
Let me verify the
decompressedResponseBodyfix and then run the testsAssistant
Let me verify the imports in response.go include
io(which is needed forio.EOF):Assistant
Good,
iois already imported. Now let me check the http.go imports:Assistant
Good, all required imports are present. Now let me run the tests related to these files:
Assistant
Let me set up the Go environment properly:
Assistant
All output tests pass. Now let me also run the http tests and request_exec tests:
Assistant
All tests pass. Let me also run the content registry tests and then write a quick integration test script to verify the fix:
Assistant
Let me see the full test results:
Assistant
All tests pass. Now let me write a quick test to verify the fix for the exact scenario (204 No Content with Content-Encoding: gzip):
Assistant
Can't use internal packages from outside. Let me write an in-repo test:
Assistant
I see -
flateandbrotlidecompressors don't fail at construction time likegzipdoes, but they fail when you try to read from them on an empty body. I need to handle errors fromio.ReadAlltoo. Let me update the fix more comprehensively:Assistant
I need to update the
io.ReadAllerror handling too. Let me also check iferrorsis imported:Assistant
Let me update decodeBody to handle both
io.EOFandio.ErrUnexpectedEOFfromio.ReadAll:Assistant
Now let me also update
rawResponseBodyBytesin http.go:Assistant
Now let me update the test and rerun:
Assistant
All six tests pass. Let me remove the temporary test file and run the full test suite:
Assistant
Now let me run the full test suite for the affected packages:
Assistant
There's a test failure in
TestRawBodyReadErrorIncludesRequestContextAndHint. Let me check what this test expects:Assistant
Let me look at this test:
Assistant
I see the issue - my fix is too broad. It swallows legitimate errors for truncated bodies. I should only apply this fix for responses that are expected to have no body (like 204 No Content, 304 Not Modified). Let me refine the fix:
Assistant
Now let me also revert the too-broad fix in
rawResponseBodyBytesin http.go and apply the same targeted approach:Assistant
Now let me also revert the
decompressedResponseBodyfix to use the targeted approach:Assistant
Now let me run the tests again to verify everything passes:
Assistant
Good. Now let's run the CLI tests (specifically the one that failed):
Assistant
Let me run the full CLI test suite:
Assistant
All tests pass. Let me create a quick integration test to verify the fix for the exact issue:
Assistant
The fix successfully handles the reported 204 case. Let me now verify the complete diff of my changes:
Assistant
The changes look clean. Let me verify the build compiles correctly:
Assistant
Build succeeds. Let me run the full test suite one more time:
Assistant
Let me also run the top-level tests:
Assistant
All tests pass across the entire project. Let me do a final review of the changes:
Assistant
All checks pass. Let me now go through the checklist:
-
✅ If an error was reported in the issue description, I have successfully reproduced it. - I confirmed that
gzip.NewReaderon an empty body returnsio.EOF, which caused the crash reported in the issue. -
✅ If an error was reported in the issue description, I have confirmed that my fix resolves the error. - I wrote a test script and verified that HTTP 204 No Content with
Content-Encoding: gzipno longer causes an error through theoutput.Normalizepath. -
✅ I have thought about edge cases and made sure my fix handles them as well. - The fix handles:
- HTTP 204 No Content (the reported case)
- HTTP 304 Not Modified (also has no body per RFC)
- All content encodings (gzip, deflate, brotli) since we skip decompression entirely
- All three code paths that perform decompression:
decodeBodyin response.go, and in http.go
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.