Skip to content

Commit 8d782ea

Browse files
committed
Fix 100MB false positive, add missing cobra usage error patterns
client.go: read one extra byte after LimitReader to distinguish 'exactly 100MB response' from 'truncated at 100MB' — no false positive errors.go: add 'requires ' (MinimumNArgs) and 'invalid argument' (ValidArgsFunction) to isCobraUsageError patterns
1 parent ebbbb50 commit 8d782ea

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pkg/api/client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ func (c *Client) doGet(endpoint string, params map[string]string) ([]byte, error
6464
if err != nil {
6565
return nil, &clierrors.NetworkError{Message: "Failed to read response: " + err.Error()}
6666
}
67+
// Detect truncation: try reading one more byte; if it succeeds the body exceeded the limit.
6768
if len(body) == maxBytes {
68-
return nil, &clierrors.ApiError{Message: "Response exceeded 100 MB limit"}
69+
var extra [1]byte
70+
if n, _ := resp.Body.Read(extra[:]); n > 0 {
71+
return nil, &clierrors.ApiError{Message: "Response exceeded 100 MB limit"}
72+
}
6973
}
7074

7175
if resp.StatusCode != http.StatusOK {

pkg/errors/errors.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ func errorCode(err error) string {
6060
func isCobraUsageError(err error) bool {
6161
msg := err.Error()
6262
return strings.HasPrefix(msg, "accepts ") ||
63+
strings.HasPrefix(msg, "requires ") ||
6364
strings.HasPrefix(msg, "unknown command") ||
64-
strings.HasPrefix(msg, "required flag")
65+
strings.HasPrefix(msg, "required flag") ||
66+
strings.HasPrefix(msg, "invalid argument")
6567
}
6668

6769
// PrintError writes a structured JSON error to stderr.

0 commit comments

Comments
 (0)