Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Error parsing this YAML file. #73

Merged
merged 1 commit into from
Jun 9, 2015
Merged

Conversation

klynton
Copy link
Contributor

@klynton klynton commented Jun 9, 2015

Hi,

As a pre-commit hook I'm checking to see that my code is able to be parsed, like so:

for file in `git diff-index --cached --diff-filter=AM --name-only HEAD`
do
  echo "Validating ${file}..."

  case "${file##*.}" in
    "pp")  puppet parser validate ${file}
           ;;

    "erb") /opt/puppet/bin/erb -P -x -T '-' ${file} | /opt/puppet/bin/ruby -c >/dev/null
           ;;

    "yaml") /opt/puppet/bin/ruby -ryaml -e "YAML.load_file '${file}'" >/dev/null
           ;;

  esac

  EXITCODE=$((EXITCODE + $?))
done

This file causes the pre-commit hook to fail with the following error:

root@klynton:puppetcode # git commit -m 'really'
Validating modules/staging/spec/fixtures/hiera.yaml...
/opt/puppet/lib/ruby/1.9.1/psych.rb:203:in `parse': (modules/staging/spec/fixtures/hiera.yaml): block sequence entries are not allowed in this context at line 2 column 12 (Psych::SyntaxError)
    from /opt/puppet/lib/ruby/1.9.1/psych.rb:203:in `parse_stream'
    from /opt/puppet/lib/ruby/1.9.1/psych.rb:151:in `parse'
    from /opt/puppet/lib/ruby/1.9.1/psych.rb:127:in `load'
    from /opt/puppet/lib/ruby/1.9.1/psych.rb:297:in `block in load_file'
    from /opt/puppet/lib/ruby/1.9.1/psych.rb:297:in `open'
    from /opt/puppet/lib/ruby/1.9.1/psych.rb:297:in `load_file'
    from -e:1:in `<main>'

################################################################
### Please fix the errors above before committing your code. ###
################################################################

root@klynton:puppetcode #

This simple change allows the YAML to be parsed.

@nibalizer
Copy link
Member

This is legit. If you would add a test to our suite do the same validation you would be my hero.

nibalizer added a commit that referenced this pull request Jun 9, 2015
Error parsing this YAML file.
@nibalizer nibalizer merged commit 125b7ec into voxpupuli:master Jun 9, 2015
klynton added a commit to klynton/bodeco_module_helper that referenced this pull request Jun 10, 2015
Adding validation to spot issues like the one found in voxpupuli/puppet-staging#73
@klynton
Copy link
Contributor Author

klynton commented Jun 10, 2015

@nibalizer Sent a PR to bodeco/bodeco_module_helper#12 with the code.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants