Syntax errors are the most common errors that we see when we develop code. It's easy to miss simple syntax when typing code, and to push failing code to a test environment. In the following example, the closing bracket to the class at the end of the file is missing:
[root@wordpress puppet]# puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Loading facts
Error: Could not retrieve catalog from remote server: Error 500 on SERVER:
Server Error: Syntax error at end of input (file: /etc/puppetlabs/code/environments/production/modules/profile/manifests/baseline.pp) on node wordpress
We can test for this failure long before it is deployed to our Puppet Master. The command puppet parser validate will give us the exact same message as the agent if we run it against the manifest. Users of the PDK will find that pdk validate runs this as one of the checks in the suite. The error from the agent run is replicated by Puppet parser validate in the following code:
[root@pe-puppet-master manifests]# puppet parser validate baseline.pp
Error: Could not parse for environment production: Syntax error at end of input (file: /etc/puppetlabs/code/environments/production/modules/profile/manifests/baseline.pp)
This is one of the simplest examples of a good practice to put into your CI/CD pipelines. You can find more good examples of adding this simple check in Chapter 8, Extending Puppet with Tasks and Discovery.