Skip to content

fix: json error formatter when files are empty #3798

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

Merged
merged 1 commit into from
Mar 18, 2025

Conversation

shyim
Copy link
Contributor

@shyim shyim commented Jan 27, 2025

Hey,

I am trying to parse the JSON output of PHPStan in Go.

When it is filled I get:

"files: { "filename.php": {}}

but when not it's

"files": []

so it changes it type from object to array and it explodes in another languages like Go:

Error: json: cannot unmarshal array into Go struct field PhpStanOutput.files of type map[string]struct { Errors int "json:\"errors\""; Messages []struct { Message string "json:\"message\""; Line int "json:\"line\""; Ignorable bool "json:\"ignorable\""; Identifier string "json:\"identifier\"" } "json:\"messages\"" }

@shyim shyim force-pushed the patch-1 branch 2 times, most recently from dd89c2c to db31a2b Compare January 27, 2025 13:04
Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

You could even go further and make everything that's string-indexed array here being encoded into stdClass. But I don't require that.

@shyim shyim requested a review from ondrejmirtes January 27, 2025 14:54
@ondrejmirtes ondrejmirtes merged commit 3b421cd into phpstan:2.1.x Mar 18, 2025
429 of 430 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

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.

None yet

2 participants