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

crash when trying to fix manifest_whitespace_closing_brace_before and trailing_comma #111

Open
zombiedk opened this issue Mar 23, 2023 · 7 comments
Labels
bug Something isn't working community

Comments

@zombiedk
Copy link

Describe the Bug

if you have these 2 errors next to each other it will crash, if you manaualy fix just one of them it work fine

ERROR: there should be a single space or newline before a closing brace on line 11 (check: manifest_whitespace_closing_brace_before)
WARNING: missing trailing comma after last element on line 11 (check: trailing_comma)

Whoops! It looks like puppet-lint has encountered an error that it doesn't
know how to handle. Please open an issue at https://github.com/rodjek/puppet-lint
and paste the following output into the issue description.

puppet-lint version: 3.3.0
ruby version: 3.0.4-p208
platform: x86_64-linux-gnu
file path: environments/testing/site-modules/kortftp/manifests/http.pp
file contents:

# nginx server for fail2unban
class kortftp::http () {
  nginx::resource::location { "${domain}_root":
    ensure              => present,
    location_cfg_append => {
      'include'       => '/etc/nginx/fastcgi_params',
      # 'fastcgi_pass'  => "127.0.1.1:${phpfpm_port}",
      'fastcgi_param' => 'SCRIPT_FILENAME $document_root$fastcgi_script_name',
      'allow'         => ['127.0.0.1', $::ipaddress],
      'deny'          => 'all',
    }

  }
}

error:

TypeError: no implicit conversion from nil to integer
/var/lib/gems/3.0.0/gems/puppet-lint-trailing_comma-check-1.0.0/lib/puppet-lint/plugins/check_trailing_comma.rb:145:in `insert'
/var/lib/gems/3.0.0/gems/puppet-lint-trailing_comma-check-1.0.0/lib/puppet-lint/plugins/check_trailing_comma.rb:145:in `fix'
/var/lib/gems/3.0.0/gems/puppet-lint-3.3.0/lib/puppet-lint/checkplugin.rb:42:in `block in fix_problems'
/var/lib/gems/3.0.0/gems/puppet-lint-3.3.0/lib/puppet-lint/checkplugin.rb:38:in `each'
/var/lib/gems/3.0.0/gems/puppet-lint-3.3.0/lib/puppet-lint/checkplugin.rb:38:in `fix_problems'
/var/lib/gems/3.0.0/gems/puppet-lint-3.3.0/lib/puppet-lint/checks.rb:67:in `block in run'
/var/lib/gems/3.0.0/gems/puppet-lint-3.3.0/lib/puppet-lint/checks.rb:65:in `each'
/var/lib/gems/3.0.0/gems/puppet-lint-3.3.0/lib/puppet-lint/checks.rb:65:in `run'
/var/lib/gems/3.0.0/gems/puppet-lint-3.3.0/lib/puppet-lint.rb:224:in `run'
/var/lib/gems/3.0.0/gems/puppet-lint-3.3.0/lib/puppet-lint/bin.rb:84:in `block in run'
/var/lib/gems/3.0.0/gems/puppet-lint-3.3.0/lib/puppet-lint/bin.rb:80:in `each'
/var/lib/gems/3.0.0/gems/puppet-lint-3.3.0/lib/puppet-lint/bin.rb:80:in `run'
/var/lib/gems/3.0.0/gems/puppet-lint-3.3.0/bin/puppet-lint:7:in `<top (required)>'
/usr/local/bin/puppet-lint:25:in `load'
/usr/local/bin/puppet-lint:25:in `<main>'

expected output

# nginx server for fail2unban
class kortftp::http () {
  nginx::resource::location { "${domain}_root":
    ensure              => present,
    location_cfg_append => { 
      'include'       => '/etc/nginx/fastcgi_params',
      # 'fastcgi_pass'  => "127.0.1.1:${phpfpm_port}",
      'fastcgi_param' => 'SCRIPT_FILENAME $document_root$fastcgi_script_name',
      'allow'         => ['127.0.0.1', $::ipaddress],
      'deny'          => 'all',
    },
  }
}
@zombiedk zombiedk added the bug Something isn't working label Mar 23, 2023
@chelnak
Copy link

chelnak commented Mar 23, 2023

@zombiedk Thanks!, this is certainly not what you want.

I see you are running ruby 3 there. puppet-lint is not yet supported on that platform, however I'll take a look and see if i can replicate your issue on a supported ruby.

In the meantime it would be great if you could run

gem list | grep puppet-lint and paste the output.

thank you!

@chelnak
Copy link

chelnak commented Mar 23, 2023

I have replicated your issue so will continue to investigate.

@chelnak
Copy link

chelnak commented Mar 23, 2023

It looks to me that the issue you are experiencing is being caused by a conflict of interest with two community plugins.

  1. puppet-lint-manifest_whitespace-check detects and fixes an issue on line 11/12 of your example
  2. puppet-lint-trailing_comma-check then tries to fix an issue at the index of the token on line 11.
  3. When trailing_comma_check tries to apply the fix (tokens.insert(idx, comma)) it fails because idx is nil and not a valid index.
  4. I think it's nil at this point because the position that the problem was originally registered at no longer exists (due to step 1).

@chelnak
Copy link

chelnak commented Mar 23, 2023

@zombiedk please can you open an issue at https://github.com/voxpupuli/puppet-lint-trailing_comma-check and link to this?

@zombiedk
Copy link
Author

puppet-lint (3.3.0, 2.4.2)
puppet-lint-absolute_classname-check (3.1.0)
puppet-lint-anchor-check (1.1.0)
puppet-lint-file_ensure-check (1.1.0)
puppet-lint-leading_zero-check (1.1.0)
puppet-lint-lookup_in_parameter-check (1.1.0)
puppet-lint-manifest_whitespace-check (0.2.9)
puppet-lint-optional_default-check (1.1.0)
puppet-lint-param-docs (1.7.6)
puppet-lint-param-types (1.0.0)
puppet-lint-params_empty_string-check (1.1.0)
puppet-lint-resource_reference_syntax (1.2.0)
puppet-lint-strict_indent-check (2.1.0)
puppet-lint-topscope-variable-check (1.2.0)
puppet-lint-trailing_comma-check (1.0.0)
puppet-lint-unquoted_string-check (2.2.0)
puppet-lint-variable_contains_upcase (1.3.0)
puppet-lint-version_comparison-check (1.1.0)
voxpupuli-puppet-lint-plugins (4.0.0)

@chelnak
Copy link

chelnak commented Mar 27, 2023

Hey thanks for that. As an aside, I see that you have two versions of puppet-lint installed. That might cause you some grief in the future.

Check out this article: https://dev.to/puppet/puppet-lint-soft-dependency-conflicts-after-updating-430l

You may benefit from cleaning up your installation.

@zombiedk
Copy link
Author

Fixed

puppet-lint (3.3.0)
puppet-lint-absolute_classname-check (3.1.0)
puppet-lint-anchor-check (1.1.0)
puppet-lint-file_ensure-check (1.1.0)
puppet-lint-leading_zero-check (1.1.0)
puppet-lint-lookup_in_parameter-check (1.1.0)
puppet-lint-manifest_whitespace-check (0.2.9)
puppet-lint-optional_default-check (1.1.0)
puppet-lint-param-docs (1.7.6)
puppet-lint-param-types (1.0.0)
puppet-lint-params_empty_string-check (1.1.0)
puppet-lint-resource_reference_syntax (1.2.0)
puppet-lint-strict_indent-check (2.1.0)
puppet-lint-topscope-variable-check (1.2.0)
puppet-lint-trailing_comma-check (1.0.0)
puppet-lint-unquoted_string-check (2.2.0)
puppet-lint-variable_contains_upcase (1.3.0)
puppet-lint-version_comparison-check (1.1.0)
voxpupuli-puppet-lint-plugins (4.0.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working community
Projects
None yet
Development

No branches or pull requests

3 participants