-
Notifications
You must be signed in to change notification settings - Fork 15
Fix JSON Marshal/Unmarshal Issues Throughout Provider #831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com>
Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR tightens JSON marshaling/unmarshaling error handling and prevents potential panics by validating inputs and using safe assertions.
- Added empty response body check before JSON unmarshal in the languages client
- Replaced ignored
json.Marshal
errors with conditional handling - Introduced safe type assertions and corrected
Decode
usage in request marshalling
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
internal/services/languages/datasource_languages.go | Use safe ProviderData assertion and nil-Api validation |
internal/services/languages/api_languages.go | Check for empty BodyAsBytes before JSON unmarshal |
internal/services/connection/datasource_connections.go | Handle json.Marshal errors when serializing connection properties |
internal/api/request.go | Simplify MarshallTo by passing obj directly to Decode |
.changes/unreleased/fixed-20250605-072914.yaml | Add changelog entry for JSON marshal/unmarshal fixes |
Comments suppressed due to low confidence (2)
internal/services/languages/datasource_languages.go:101
- Consider adding unit tests for the new
!ok
branch and thenil Api
branch to ensure these error paths are covered.
providerClient, ok := req.ProviderData.(*api.ProviderClient)
internal/services/languages/api_languages.go:47
- Add a unit test to simulate an empty response body and verify that
errors.New("empty response body")
is returned as expected.
if len(response.BodyAsBytes) == 0 {
Co-authored-by: mattdot <266258+mattdot@users.noreply.github.com>
This PR addresses several JSON marshaling/unmarshaling and type assertion issues that could lead to poor error handling, silent failures, or runtime panics.
Issues Fixed
1. Empty Response Body Validation
File:
internal/services/languages/api_languages.go
2. Ignored JSON Marshal Errors
File:
internal/services/connection/datasource_connections.go
_
, potentially causing invalid state3. Unsafe Type Assertion
File:
internal/services/languages/datasource_languages.go
4. Incorrect JSON Decode Usage
File:
internal/api/request.go
&obj
toDecode()
whenobj
is already an interface{} was incorrectobj
directly since it should already be a pointerValidation
These fixes improve error handling, prevent potential panics, and ensure proper JSON marshaling/unmarshaling throughout the provider.
Fixes #817.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
http://168.63.129.16:80/machine/
/usr/bin/python3 -u bin/WALinuxAgent-2.13.1.1-py3.9.egg -collect-logs
(http block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.