[PUP-8140] NoMethodErrors involving Puppet::Face instances do not have a useful error message Created: 2017/11/09  Updated: 2018/02/05  Resolved: 2017/11/16

Status: Closed
Project: Puppet
Component/s: None
Affects Version/s: PUP 4.10.9, PUP 5.3.3
Fix Version/s: PUP 4.10.10, PUP 5.3.4, PUP 5.4.0

Type: Bug Priority: Normal
Reporter: Charlie Sharpsteen Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: cs_pr_review
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Relates
Template:
Team: Platform Core
Sprint: Platform Core KANBAN
Method Found: Customer Feedback
Release Notes: Bug Fix
Release Notes Summary: Error messages from Puppet::Face objects now include the name and version number of the face.
QA Risk Assessment: No Action

 Description   

The Puppet::Face class does not define a useful text representation for use in some error messages — I.E. NoMethodError. This makes errors involving missing methods on Puppet Faces especially difficult to track down. Puppet Faces allow multiple versions, so these errors are easy to create by third-party modules defining a new Face version that other Puppet components don't expect.

Reproduction Case.

  • Install the latest puppet-agent 4.10.x on CentOS 7:

rpm -Uvh http://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm
yum install -y puppet-agent

  • Create a module containing a Puppet Face that can fail due to multiple versions:

mkdir -p /etc/puppetlabs/code/environments/production/modules/test_face/lib/puppet/application
cat <<EOF > /etc/puppetlabs/code/environments/production/modules/test_face/lib/puppet/application/foo.rb
require 'puppet/application/face_base'
 
class Puppet::Application::Foo < Puppet::Application::FaceBase
end
EOF
 
mkdir -p /etc/puppetlabs/code/environments/production/modules/test_face/lib/puppet/face
cat <<EOF > /etc/puppetlabs/code/environments/production/modules/test_face/lib/puppet/face/foo.rb
Puppet::Face.define(:foo, '0.0.1') do
  action :bar do
    when_invoked do |*args|
      puts "Bar action called!"
    end
  end
 
  action :baz do
    when_invoked do |*args|
      puts "Baz action called!"
      Puppet::Face[:foo, :current].bar
    end
  end
end
 
Puppet::Face.define(:foo, '0.0.2') do
  action :bim do
    when_invoked do |*args|
      puts "Bim action called!"
    end
  end
end
EOF

  • Run the face to generate a failure: /opt/puppetlabs/puppet/bin/puppet foo baz

Outcome

The error message indicates no baz method is avaiailble, but provides no clue that Face versions are coming into play:

# /opt/puppetlabs/puppet/bin/puppet foo baz
Baz action called!
Error: undefined method `bar' for #<Puppet::Interface:0x00000004668948>
Error: Try 'puppet help foo baz' for usage

Expected Outcome

The error message should include the face name and version number, as provided by the to_s method of the Puppet::Interface class:

# /opt/puppetlabs/puppet/bin/puppet foo baz
Baz action called!
Error: undefined method `bar' for Puppet::Face[:foo, v0.0.2]:Puppet::Interface
Error: Try 'puppet help foo baz' for usage



 Comments   
Comment by Charlie Sharpsteen [ 2017/11/13 ]

Thanks for the merge Henrik Lindberg! I'd also like to get this into the 5.x series. Are we still merging 4.10.x into master, or should I open a seperate PR for that?

Comment by Henrik Lindberg [ 2017/11/13 ]

Charlie Sharpsteen We have already merged up 4.10, to 5.3, and to master. Typically do that asap after the merge to 4.10 unless there are traffic accidents in the way.

Comment by Charlie Sharpsteen [ 2017/11/13 ]

Awesome! Thanks for the sanity check.

Comment by Melissa Stone [ 2017/11/16 ]

This has passed CI

Generated at Wed Jan 22 03:16:19 PST 2020 using JIRA 7.7.1#77002-sha1:e75ca93d5574d9409c0630b81c894d9065296414.