Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-9400

Puppet Parser cannot handle "case $:xxx:{ default: {} }" block

    XMLWordPrintable

Details

    • Froyo
    • Needs Assessment
    • Bug Fix
    • The Ruby API of the PN Transformer (producing output for parsed AST) could not handle some empty constructs and would produce an error instead of generating a Nop Expression.
    • Needs Assessment

    Description

      Puppet Version: 6.1.0
      Puppet Server Version: does not apply**
      OS Name/Version: Windows but does not apply

      I am using puppet internals (puppet parser) to parse puppet manifests into JSON (puppet structured AST).

      I have noticed that PNTransformer cannot transform this block 

      class breakme {
        case "test" {
          default: {}
        }
      }

      into JSON and crashes 

      Visitor Error: the configured receiver (Puppet::Pops::Model::PNTransformer) can't handle instance of: NilClass (RuntimeError)

      (see crash stack trace attached).

       
      The reason of this is because the instruction pretty much produces nothing AND PNTransformer has no method to visit the transform_NilClass (puppet server even thinks it's illegal, This 'case' statement has no effect.). However, the instruction being illegal is irrelevant, as the puppet parser has to parse the AST structure correctly anyway.
       
      Please see the puppet-parser-test-current.rb and puppet-parser-test-fixed.rb as self-containing examples
      Desired Behavior:

      **It should resolve the default section into, for example, a "nop" instruction:

      {"^":["class",{"#":["name","breakme","body",[{"^":["case","test",[{"#":["when",[{"^":["default"]}],"then",[{"^":["nop"]}]]}]]}]]}]}

      Actual Behavior:

      **It crashes with Visitor Error: the configured receiver (Puppet::Pops::Model::PNTransformer) can't handle instance of: NilClass (RuntimeError)

       

      Solution:
      The solution would be to add this method to the PNTransformer class:

      class Puppet::Pops::Model::PNTransformer 
        def transform_NilClass(e)
          Puppet::Pops::PN::Call.new('nop')
        end
      end

       Or, it should raise appropriate exception of the expression being illegal, instead of crashing

      Attachments

        Activity

          People

            Unassigned Unassigned
            desertkun Alex Siryi
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Zendesk Support