Skip to content
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

fix: json error formatter when files are empty #3798

Open
wants to merge 1 commit into
base: 2.1.x
Choose a base branch
from

Conversation

shyim
Copy link

@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.

src/Command/ErrorFormatter/JsonErrorFormatter.php Outdated Show resolved Hide resolved
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