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.code$ 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:codeERROR: Parse response error ERROR: Caught error: EOFHere is the full log:
code Assistant
Let me start by exploring the repository structure and understanding the codebase, then find the relevant code that handles response parsing.
Assistant
Now let me find where the response body is actually decoded/parsed. The error is "Parse response error" and "Caught error: EOF". Let me search for where the body is decoded into structured data.
Assistant
Let me look at where the response body is parsed into
resp.Body. The issue is about decoding an empty body. Let me search the http.go file around lines 300-420 where formatResponse is called after making a request.Assistant
Now let me look at
normalizeHTTPResponse, which is where the body is likely decoded:Assistant
Now let me look at
output.Normalize:Assistant
The
decodeBodyhandles empty body correctly. The stack trace mentionsoperation.goandMakeRequestAndFormat. Let me look at the operation handling code path:Assistant
The stack trace mentions
operation.go:142andrequest.go:568andMakeRequestAndFormat. The current repo structure has been refactored. Let me search for the operation command handler that makes requests.Assistant
The current
decodeBodyreturnsnil, nil, nilwhenlen(raw) == 0. But the issue mentions "Decoding response from gzip" and a panic. Let me reproduce the scenario with a 204 response with gzip Content-Encoding and empty body to see if the current code has the bug:Assistant
Found the likely bug!
gzip.NewReader(r)on an empty reader returnsio.EOFbecause it can't read the gzip header. Soreg.Decompressreturns an error, anddecodeBodyreturns"decompressing response: EOF". Let me write a reproduction test:Assistant
Let me just rewrite the test cleanly:
Assistant
I've reproduced the bug. The error is
decompressing response: EOFbecausegzip.NewReaderon an empty body returnsio.EOF. Let me look at the deflate decompress too:Assistant
I've reproduced the bug:
decompressing response: EOF. The root cause isdefaultGzipDecompresscallinggzip.NewReader(r)which returnsio.EOFwhen the input stream is empty (no gzip header to read). This affectsdecodeBodyand other decompress call sites (rawResponseBodyBytes,decompressedResponseBody).Let me look at the imports in registry.go and existing tests for decompress:
Assistant
Now let me implement the fix in
defaultGzipDecompressto handle empty input gracefully:Assistant
Now let me implement the fix. I'll modify
defaultGzipDecompressto handle empty input gracefully, and add theerrorsimport:Assistant
Let me reconsider the peek logic. A truncated gzip stream (1-9 bytes) should still error, but a fully empty stream (0 bytes) should be treated as empty. Let me refine to only handle
io.EOF:Assistant
Now let me run the reproduction test to confirm the fix:
Assistant
The fix works. Now let me run the existing content and output tests to make sure nothing broke:
Assistant
Now let me run the cli tests which cover the HTTP request/response handling paths:
Assistant
All tests pass. Now let me write a more end-to-end reproduction to confirm the full operation path (with a 204 + gzip + generated operation). Let me also test the raw body and streaming paths to ensure edge cases:
Assistant
The test file is in package
contentbutregis defined inregistry_test.gowhich is alsopackage content. Wait,var reg = content.Default()- this means the test file ispackage content_test(external test package) that importscontent. My test file declarespackage content. Let me check the test package.Assistant
The truncated stream test shows err==nil, which is unexpected. Let me check the actual file content and debug:
Assistant
The code looks correct. Let me debug the truncated test. Maybe
errors.Is(io.ErrUnexpectedEOF, io.EOF)is actually true in Go? Let me check.Actually, in Go's standard library,
io.ErrUnexpectedEOFis defined aserrors.New("unexpected EOF"). Anderrors.Ischecks if the target equals the error or any wrapped error. Sinceio.ErrUnexpectedEOFis not wrappingio.EOF,errors.Is(io.ErrUnexpectedEOF, io.EOF)should befalse.Wait, but maybe
bufio.Reader.Peekwith a 2-byte input and default buffer size... Let me actually write a quick debug test to see what Peek returns.Actually wait, maybe the issue is that
errors.Is(err, io.EOF)returns TRUE for io.ErrUnexpectedEOF. Let me check the Go source. Actually no.Hmm, but the test result clearly says err==nil for the 2-byte case. That means either:
- Peek returned nil error (unlikely for 2 bytes < 10)
- errors.Is(err, io.EOF) returned true → returned empty reader, nil
Let me check: in Go, does
errors.Is(io.ErrUnexpectedEOF, io.EOF)return true? Let me test this directly.Assistant
Interesting!
bufio.Reader.Peek(10)on a 2-byte input returnsio.EOF(notio.ErrUnexpectedEOF), anderrors.Is(err, io.EOF)is true. But the difference is the number of bytes returned: empty returns 0 bytes, truncated returns the partial bytes. Let me fix the logic to check the byte count:Assistant
Peekreturns[]byte, so I needlen(n):Assistant
All tests pass, including the truncated stream test. Let me verify the final state of the function:
Assistant
Now let me run the full output test again and the broader test suite to ensure everything passes:
Assistant
The fix at the content package level handles all decompress call sites. Let me run the full repo test suite to be thorough:
Assistant
All tests pass across the entire repository. Now let me clean up my temporary reproduction test files before submitting:
Assistant
Only the source file is modified. Let me view the final diff:
Assistant
The diff is clean. Let me run the content and output tests once more after cleanup to confirm everything still passes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.