Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled error case #691

Closed
cbowman0 opened this issue Mar 30, 2017 · 7 comments
Closed

Unhandled error case #691

cbowman0 opened this issue Mar 30, 2017 · 7 comments
Labels

Comments

@cbowman0
Copy link
Contributor

I've been attempting to reduce a manifest to report a case of puppet-lint --fix mangling a file. In doing so, I ended up with this:

puppet-lint version: 2.2.1
ruby version: 2.0.0-p648
platform: universal.x86_64-darwin16
file path: init.pp
file contents:

class test {

	file {
		"/usr/local/processor.json":
			require => File["/usr/local"],
			notify => Service["processor"],
			ensure => "file",
			backup => '.bak';

		"/usr/local/proxy.json":
			tag => proxy,
			require => File["/usr/local"],
			notify => Service["processor"],
			ensure => "file",
			backup => '.bak';


		"/etc/bar.conf":
			# notify => Service["bar"],
			ensure => "file",
			content => template("bar.conf");

		"/usr/local/log":
			require => File["/usr/local"],
			ensure => "directory",
			mode => "0755",
			owner => "root",
			group => "root";
	}
}

error:

NoMethodError: undefined method `next_token_of' for nil:NilClass
/Users/cbowman/git/resources/resources_puppet-lint/gems/puppet-lint-2.2.1/lib/puppet-lint/plugins/check_resources.rb:55:in `fix'
/Users/cbowman/git/resources/resources_puppet-lint/gems/puppet-lint-2.2.1/lib/puppet-lint/checkplugin.rb:41:in `block in fix_problems'
/Users/cbowman/git/resources/resources_puppet-lint/gems/puppet-lint-2.2.1/lib/puppet-lint/checkplugin.rb:38:in `each'
/Users/cbowman/git/resources/resources_puppet-lint/gems/puppet-lint-2.2.1/lib/puppet-lint/checkplugin.rb:38:in `fix_problems'
/Users/cbowman/git/resources/resources_puppet-lint/gems/puppet-lint-2.2.1/lib/puppet-lint/checks.rb:61:in `block in run'
/Users/cbowman/git/resources/resources_puppet-lint/gems/puppet-lint-2.2.1/lib/puppet-lint/checks.rb:56:in `each'
/Users/cbowman/git/resources/resources_puppet-lint/gems/puppet-lint-2.2.1/lib/puppet-lint/checks.rb:56:in `run'
/Users/cbowman/git/resources/resources_puppet-lint/gems/puppet-lint-2.2.1/lib/puppet-lint.rb:191:in `run'
/Users/cbowman/git/resources/resources_puppet-lint/gems/puppet-lint-2.2.1/lib/puppet-lint/bin.rb:59:in `block in run'
/Users/cbowman/git/resources/resources_puppet-lint/gems/puppet-lint-2.2.1/lib/puppet-lint/bin.rb:56:in `each'
/Users/cbowman/git/resources/resources_puppet-lint/gems/puppet-lint-2.2.1/lib/puppet-lint/bin.rb:56:in `run'
/Users/cbowman/git/resources/resources_puppet-lint/gems/puppet-lint-2.2.1/bin/puppet-lint:7:in `<top (required)>'
/Users/cbowman/git/resources/resources_puppet-lint/bin/puppet-lint:19:in `load'
/Users/cbowman/git/resources/resources_puppet-lint/bin/puppet-lint:19:in `<main>'
@cbowman0
Copy link
Contributor Author

Attached file since the tabs appear to make a difference.

init.pp.txt

@cbowman0
Copy link
Contributor Author

I've tracked this down to fix of the ensure_first_param check. The following condition must happen:

class test {
  file {
 
 
    'foo':
      mode   => '0644',
      ensure => directory;
  }
}

The first two lines before the 'foo' resource are lines with a single space on them. The two spaces are critical to cause this failure.

When puppet-lint removes those spaces (tokens are deleted, I suspect), then the value of the start attribute of the resources hash for the problem resource (tokens[problem[:resource][:start]]) points to <Token :NAME (mode) @6:7>. If only the ensure_first_params check is run, then the value of the token is <Token :NEWLINE (\n) @5:11>.

The contents of resource_indexs could be cached from a request before the token was removed, so the contents will be wrong if the contents of the token array is changed. Changing lib/puppet-lint/data.rb as follows corrects this:

     def resource_indexes
-      @resource_indexes ||= begin
+      @resource_indexes = begin
         marker = 0

@cbowman0
Copy link
Contributor Author

Well, that reduces performance considerably.

Can the delete method for the token array be overridden to also set the resource_indexes to nil? Any other way to trigger resource_indexes to regenerate?

@rodjek rodjek added the bug label Apr 4, 2017
@djtecha
Copy link

djtecha commented May 12, 2017

I also had this issue but it was caused by having a training whitespace after my Class chains:

Class['xfsprogs'] -> Class['partitions::query'] <EXTRA SPACE HERE>

@cbowman0
Copy link
Contributor Author

I suspect the methods provided in #694 expanded to reset resource_indexes (and others) to nil when tokens are added or removed would resolve this issue.

@rodjek
Copy link
Owner

rodjek commented Aug 21, 2017

Sorry for the delay in getting back to this. @cbowman0, @djtecha I believe this has been fixed up in the 2.3.0 release, but this issue didn't get flagged properly.

Can you check and confirm that upgrading to 2.3.0 resolves this for you?

@cbowman0
Copy link
Contributor Author

Looks like it does. Thanks for following up.

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

No branches or pull requests

3 participants