[PUP-8984] Add JSON output option to `puppet parser validate` Created: 2017/05/08  Updated: 2019/07/06  Resolved: 2019/06/12

Status: Resolved
Project: Puppet
Component/s: None
Affects Version/s: None
Fix Version/s: PUP 6.5.0

Type: Improvement Priority: Major
Reporter: James Pogran Assignee: Jesse Scott
Resolution: Fixed Votes: 2
Labels: resolved-issue-added
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
causes PUP-9815 `bundle exec rake syntax` reports inv... Resolved
Template:
Epic Link: PDK Maintenance
Team: Puppet Developer Experience
Release Notes: Enhancement
Release Notes Summary: The `puppet parser validate` subcommand now supports a `--render-as=json` option to output validate errors in a machine readable JSON format.

Additionally, when passed multiple target files, `puppet parser validate` will now continue validating additional files after a parse error instead of halting immediately on the first error encountered. (Note: It will still only return a maximum of one parse error per file.)
QA Risk Assessment: Needs Assessment

 Description   

Running the following works, but still outputs plain text even though json is requested:

~ be puppet parser validate ~/Desktop/example2.pp --render-as json
Error: Could not parse for environment production: Syntax error at 'ensure' at /Users/jpogran/Desktop/example2.pp:4:2

This is important as some downstream tooling (i.e. our VSCode extension) would like to have structured input to parse. While the above example is one line, other errors span multiple, making parsing a brittle affair.

A suggestion was to use puppet's loggin facility to log to a file and then parse that, but puppet parser validate does not recognize the --logdir paramter.



 Comments   
Comment by Henrik Lindberg [ 2017/05/09 ]

Structured JSON output is supported as output, but the puppet parser command has no way of switching to using that.
(PS: the Catalog Preview application configures JSON output. So for parser validate it is basically just a matter of logging to a tmp file with .json extension and then sending the finished file to stdout).

Comment by Jesse Scott [ 2018/07/03 ]

I have a proof of concept for JSON output done, do folks have strong feelings about --render-as vs --format for the flag? --render-as seems to be used a lot of places in puppet but `puppet parser dump` already implements a --format option.

Comment by Kris Bosland [ 2019/04/29 ]

Merged into master at bae2d75.

Comment by Jesse Scott [ 2019/06/12 ]

Josh Cooper I added release notes this afternoon so this is ready to resolve as far as I know.

Generated at Tue Jul 14 18:34:14 PDT 2020 using Jira 8.5.2#805002-sha1:a66f9354b9e12ac788984e5d84669c903a370049.