Skip to content

Handle discarded io.ReadAll errors in client.go #103

@ewega

Description

@ewega

Problem

There are 12 instances of body, _ := io.ReadAll(resp.Body) in internal/devlake/client.go. The error from io.ReadAll is silently discarded.

If the TCP connection resets mid-response (possible with flaky networks, Azure Container Instances timing out, or proxy interruptions), this produces an empty or truncated body, which then fails with a confusing json.Unmarshal error:

unexpected end of JSON input

Instead of a clear:

reading response body: connection reset by peer

Fix

Replace all 12 instances of:
go body, _ := io.ReadAll(resp.Body)

With:
go body, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("reading response: %w", err) }

For functions that return error only (DeleteConnection, DeleteScope, DeleteProject), adjust the return accordingly.

Acceptance Criteria

  • All io.ReadAll calls in client.go handle errors
  • Error messages clearly indicate "reading response" vs "parsing JSON"
  • go build ./... and go test ./... pass

Metadata

Metadata

Assignees

Labels

refactorCode restructure, no behavior change

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions