Skip to content

fix: avoid panic parsing array-shaped REST error bodies - #1183

Merged
Kirdock merged 1 commit into
dynatrace-oss:mainfrom
knQzx:fix/rest-array-error-nil-panic
Jul 21, 2026
Merged

Kirdock merged 1 commit into
dynatrace-oss:mainfrom
knQzx:fix/rest-array-error-nil-panic

Conversation

@knQzx

@knQzx knQzx commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Why this PR?

any non-2xx classic-API response whose body is a JSON array without an error field (e.g. [{"code":400}]) panics the provider with a nil-pointer dereference

What has changed?

Envelope and unmarshalError now guard envs[0].Error != nil on the array branch, like the existing single-object branch already does

How does it do it?

adds && envs[0].Error != nil to the array-branch condition in dynatrace/rest/error.go and dynatrace/rest/request.go, so a shape-drifted array body falls through instead of dereferencing nil

How is it tested?

added a table test in error_test.go for array/object bodies with and without the error field; it panics on the old code and passes on the new

How does it affect users?

a malformed or array-shaped error response no longer crashes the provider mid-operation

Issue: N/A

the single-object branch guards env.Error != nil but the array branch did
not, so a non-2xx body like [{"code":400}] dereferenced a nil error and
panicked the provider. guard envs[0].Error != nil on the array branch too

@Kirdock Kirdock left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for your contribution!
LGTM

@Kirdock
Kirdock merged commit 582e618 into dynatrace-oss:main Jul 21, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants