Sometimes when code is mounted over a network share or docker shared volume and bad characters are present in puppet source code being tested onceover will crash
Expected result
Print an error message telling user to fix the bad encoding
Actual result
bundle exec onceover run spec --puppetfile Puppetfile.onceover
INFO -> Using Puppetfile 'Puppetfile.onceover'
INFO -> Updating module /shared/.onceover/etc/puppetlabs/code/environments/production/modules/stdlib
<<many lines snipped>>
INFO -> Updating module /shared/.onceover/etc/puppetlabs/code/environments/production/modules/puppet_enterprise
Error while running: #<ArgumentError: invalid byte sequence in US-ASCII>
Analysis
Modifying the onceover source code to print out the lines being evaluated reveals the cause - invalid characters in the puppetlabs-docker module's comments (fancy quotes?):
class docker::service (
# == Define: docker::stack
#
# A define that deploys Docker stacks or compose v3
#
# == Paramaters
#
# [*ensure*]
# This ensures that the stack is present or not.
# Defaults to present
#
# [*stack_name*]
# The name of the stack that you are deploying
# Defaults to undef
#
# [*bundle_file*]
# Path to a Distributed Application Bundle file
# Please note this is experimental
# Defaults to undef
#
# [*compose_file*]
# Path to a Compose file
# Defaults to undef
#
# [*prune*]
# Prune services that are no longer referenced
# Defaults to undef
#
# [*resolve_image*]
# Query the registry to resolve image digest and supported platforms
# Only accepts (“always”|“changed”|“never”)
Error while running: #<ArgumentError: invalid byte sequence in US-ASCII>
/usr/local/bundle/gems/onceover-3.12.1/lib/onceover/controlrepo.rb:644:in `find_classname'
/usr/local/bundle/gems/onceover-3.12.1/lib/onceover/controlrepo.rb:633:in `block in get_classes'
/usr/local/bundle/gems/onceover-3.12.1/lib/onceover/controlrepo.rb:632:in `each'
/usr/local/bundle/gems/onceover-3.12.1/lib/onceover/controlrepo.rb:632:in `get_classes'
/usr/local/bundle/gems/onceover-3.12.1/lib/onceover/controlrepo.rb:178:in `block in classes'
/usr/local/bundle/gems/onceover-3.12.1/lib/onceover/controlrepo.rb:177:in `each'
/usr/local/bundle/gems/onceover-3.12.1/lib/onceover/controlrepo.rb:177:in `classes'
/usr/local/bundle/gems/onceover-3.12.1/lib/onceover/controlrepo.rb:57:in `classes'
/usr/local/bundle/gems/onceover-3.12.1/lib/onceover/class.rb:12:in `initialize'
/usr/local/bundle/gems/onceover-3.12.1/lib/onceover/testconfig.rb:62:in `new'
/usr/local/bundle/gems/onceover-3.12.1/lib/onceover/testconfig.rb:62:in `block in initialize'
/usr/local/bundle/gems/onceover-3.12.1/lib/onceover/testconfig.rb:62:in `each'
/usr/local/bundle/gems/onceover-3.12.1/lib/onceover/testconfig.rb:62:in `initialize'
/usr/local/bundle/gems/onceover-3.12.1/lib/onceover/cli/run.rb:49:in `new'
/usr/local/bundle/gems/onceover-3.12.1/lib/onceover/cli/run.rb:49:in `block (2 levels) in command'
/usr/local/bundle/gems/cri-2.15.3/lib/cri/command.rb:359:in `run_this'
/usr/local/bundle/gems/cri-2.15.3/lib/cri/command.rb:296:in `run'
/usr/local/bundle/gems/cri-2.15.3/lib/cri/command.rb:314:in `run'
/usr/local/bundle/gems/cri-2.15.3/lib/cri/command.rb:314:in `run'
/usr/local/bundle/gems/onceover-3.12.1/bin/onceover:7:in `<top (required)>'
/usr/local/bundle/bin/onceover:29:in `load'
/usr/local/bundle/bin/onceover:29:in `<top (required)>'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli/exec.rb:74:in `load'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli/exec.rb:74:in `kernel_load'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli/exec.rb:28:in `run'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli.rb:424:in `exec'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli.rb:27:in `dispatch'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/cli.rb:18:in `start'
/usr/local/bundle/gems/bundler-1.16.6/exe/bundle:30:in `block in <top (required)>'
/usr/local/bundle/gems/bundler-1.16.6/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/usr/local/bundle/gems/bundler-1.16.6/exe/bundle:22:in `<top (required)>'
/usr/local/bundle/bin/bundle:104:in `load'
/usr/local/bundle/bin/bundle:104:in `<main>'
Proposed fix
Catch the ArgumentError and print a warning message
Overview
Sometimes when code is mounted over a network share or docker shared volume and bad characters are present in puppet source code being tested onceover will crash
Expected result
Print an error message telling user to fix the bad encoding
Actual result
Analysis
Modifying the onceover source code to print out the lines being evaluated reveals the cause - invalid characters in the puppetlabs-docker module's comments (fancy quotes?):
Proposed fix
Catch the ArgumentError and print a warning message