Jira (PUP-10094) Implement a PAL parse() with custom validation handling

6 views
Skip to first unread message

Ewoud Kohl van Wijngaarden (JIRA)

unread,
Oct 6, 2019, 6:27:03 AM10/6/19
to puppe...@googlegroups.com
Ewoud Kohl van Wijngaarden created an issue
 
Puppet / Improvement PUP-10094
Implement a PAL parse() with custom validation handling
Issue Type: Improvement Improvement
Assignee: Unassigned
Created: 2019/10/06 3:26 AM
Priority: Normal Normal
Reporter: Ewoud Kohl van Wijngaarden

The use case is puppet-syntax where it's desired to fully parse a file and show all warnings/errors. This is useful in CI or other systems. Currently it's using a Puppet face but this is deprecated. In https://github.com/voxpupuli/puppet-syntax/pull/108 I've investigated switching to Puppet PAL but ran into limitations. Internally it's using the IssueReporter class that's inflexible.

Quoting Henrik Lindberg from https://github.com/voxpupuli/puppet-syntax/pull/108#issuecomment-538725665

You are correct - there is no PAL parse() operation without validation. That means it will end up in the standard issueReporter (which is only somewhat configurable).
The way to capture the output would be by having a logger - i.e. similar to logging to a file ending with .json which makes the logger write json instead of formatted text.
I think it is reasonable to add a feature to PAL to make it possible to give parse a kind of "acceptor" to get warnings/errors etc. When implementing that we can make sure it only exposes public API.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Henrik Lindberg (JIRA)

unread,
Oct 6, 2019, 10:09:03 AM10/6/19
to puppe...@googlegroups.com
Henrik Lindberg commented on Improvement PUP-10094
 
Re: Implement a PAL parse() with custom validation handling

In order not to break the PAL API, I suggest we add validation methods similar to the same for parsing:

Puppet::PAL::Compiler#validate_string(String source) >> Tuple[AST, Array[Hash]]
Puppet::PAL::Compiler#validate_file(String file_name) >> Tuple[AST, Array[Hash]]

These would parse and validate and return all found issues as an Array of hashes where each hash describes one issue as follows:

# example from IssueReporter that does this for purpose of logging
{
      :level => :warning, # :error, :warning, :deprecation, :ignore
      :message => issue.format(args),
      :arguments => args,
      :issue_code => issue.issue_code,
      :file => semantic.file, # semantic is an AST object
      :line => semantic.line,
      :pos => semantic.pos,
}

The validate methods should include all reported issues - including :deprecated and :ignore - it would be up to the reporter to handle those as warnings, information, etc. Also, the settings max_error, max_warnings etc. should not have any effect - it should simply return all reported.

With the above all but one "internal API leakage" would be fixed - the args key would be the values given to the issue as arguments - and this could be some object that we do not intend to expose as API. This can be solved by not surfacing the arguments, or to do a serialization of them to for example a rich data hash (would need to check what happens when turning non-rich-data to a data hash for example an arbitrary Ruby Class, instance of arbitrary ruby Class, and specifically an Error).

Rob Braden (JIRA)

unread,
Oct 7, 2019, 1:02:03 PM10/7/19
to puppe...@googlegroups.com

Rob Braden (JIRA)

unread,
Oct 7, 2019, 1:02:03 PM10/7/19
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages