Syntax errors

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 8Extending Puppet with Tasks and Discovery.

Syntax error checkers like Puppet parser validate scan through the code until they find a line that they cannot resolve. Often, these errors are on the line above the reported failure! Always check the line above the reported line. The following error was actually a missing comma on line 4 of the example.ppError: Could not parse for environment production: Syntax error at 'source' (file: /Users/rary/workspace/packt/manifests/example.pp, line: 5, column: 5)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.23.130