Skip to content

Add nil checks for generated API client response bodies #58

@coderabbitai

Description

@coderabbitai

Description

Throughout the codebase, generated API client response fields (e.g., JSON200, JSON202, JSON201) are accessed directly without nil checks. These fields are only populated when the response body deserializes successfully. A response with the expected status code but an empty or malformed body will leave these fields nil, causing a nil pointer panic.

Context

This pattern was identified during review of PR #57 (specifically in internal/api/providers/resource.go around line 153 where createResp.JSON202.Id is accessed), but it appears to be a widespread pattern throughout the codebase.

Proposed Solution

Add nil checks before dereferencing any generated client response body fields, for example:

  • Check if resp.JSON200 == nil before accessing resp.JSON200.Field
  • Return a descriptive error when the response body is nil despite receiving the expected status code

Related

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions