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

Hash of hashes with long keys causes irrational warnings and crashes --fix #424

Closed
TomOnTime opened this issue Jun 9, 2015 · 4 comments · Fixed by #621
Closed

Hash of hashes with long keys causes irrational warnings and crashes --fix #424

TomOnTime opened this issue Jun 9, 2015 · 4 comments · Fixed by #621
Milestone

Comments

@TomOnTime
Copy link

puppet-lint --fix example.pp crashes with this code.

#
class example (
  $tiername,
  $external_ip_base,
) {
  stacklb::external::ssl_listener { "${tiername}-1":
    id     => 1,
    inputs => {
      'ny' => {
        "${external_ip_base}.16:443"  => $stacklb::external::params::ssl_wc_san,
        "${external_ip_base}.17:443"  => $stacklb::external::params::ssl_wc_san,
        "${external_ip_base}.30:443"  => $stacklb::external::params::ssl_wc_san,
        "${external_ip_base}.18:443"  => $stacklb::external::params::ssl_wc_san,
        '10.0.0.10:443'               => $stacklb::external::params::ssl_wc_se_internal,
        "${external_ip_base}.24:443"  => $stacklb::external::params::ssl_misc,
        "${external_ip_base}.140:443" => $stacklb::external::params::ssl_wc_san,
        "${external_ip_base}.141:443" => $stacklb::external::params::ssl_wc_san,
        "${external_ip_base}.154:443" => $stacklb::external::params::ssl_wc_san,
        "${external_ip_base}.142:443" => $stacklb::external::params::ssl_wc_san,
        "${external_ip_base}.148:443" => $stacklb::external::params::ssl_misc,
      },
      'or' => {
        '10.10.100.16:443' => $stacklb::external::params::ssl_wc_san,
        '10.10.100.17:443' => $stacklb::external::params::ssl_wc_san,
        '10.10.100.30:443' => $stacklb::external::params::ssl_wc_san,
        '10.10.100.18:443' => $stacklb::external::params::ssl_wc_san,
        '10.0.0.10:443'    => $stacklb::external::params::ssl_wc_se_internal,
        '10.10.100.24:443' => $stacklb::external::params::ssl_misc,
      }
    }
  }
}

Without --fix you get conflicting requirements. As-is, it gives these warnings:

$ puppet-lint   example.pp 
ERROR: example not in autoload module layout on line 2
WARNING: indentation of => is not properly aligned on line 10
WARNING: indentation of => is not properly aligned on line 11
WARNING: indentation of => is not properly aligned on line 12
WARNING: indentation of => is not properly aligned on line 13
WARNING: indentation of => is not properly aligned on line 14
WARNING: indentation of => is not properly aligned on line 15
WARNING: indentation of => is not properly aligned on line 16
WARNING: indentation of => is not properly aligned on line 17
WARNING: indentation of => is not properly aligned on line 18
WARNING: indentation of => is not properly aligned on line 19
WARNING: indentation of => is not properly aligned on line 20
WARNING: line has more than 80 characters on line 14

I hacked puppet-lint to expose what alignment it was expecting. When I aligned things that way, it warned me that this alignment was incorrect too. No wonder --fix crashes.

@rnelson0
Copy link
Collaborator

@TomOnTime I am closing this as a duplicate of #416, please re-open it if you feel that is incorrect.

@TomOnTime
Copy link
Author

This is a different issue. The test case still exhibits the same problem with version 2.0.0

By the way... it would be great if the warning output what column was expected for =>

@TomOnTime
Copy link
Author

@rnelson0 P.S. I don't see how to re-open the issue. (sorry!)

@rnelson0
Copy link
Collaborator

This issue is the result of check_whitespaces.rb looking at the length of the previous indent token, then the previous code token, and getting an unexpected value. By adding a debug print statement puts "token is #{token.inspect} with #{token.prev_code_token.inspect}" at the end of the latter block, we can see what the tokens and previous codes look like for lines 10 and 14:

        "${external_ip_base}.16:443"  => $stacklb::external::params::ssl_wc_san,           #line 10
        '10.0.0.10:443'               => $stacklb::external::params::ssl_wc_se_internal,   #line 15

token is <Token :INDENT (        ) @10:1> with nil
token is <Token :DQPRE () @10:9> with <Token :LBRACE ({) @9:15>
token is <Token :VARIABLE (external_ip_base) @1:1> with nil
token is <Token :VARIABLE (external_ip_base) @10:11> with <Token :DQPRE () @10:9>
token is <Token :DQPOST (.16:443) @10:29> with <Token :VARIABLE (external_ip_base) @10:11>
token is <Token :WHITESPACE (  ) @10:37> with nil
token is <Token :FARROW (=>) @10:39> with <Token :DQPOST (.16:443) @10:29>
token is <Token :WHITESPACE ( ) @10:41> with nil
token is <Token :VARIABLE (stacklb::external::params::ssl_wc_san) @10:42> with <Token :FARROW (=>) @10:39>
token is <Token :COMMA (,) @10:80> with <Token :VARIABLE (stacklb::external::params::ssl_wc_san) @10:42>
token is <Token :NEWLINE (
) @10:81> with nil

token is <Token :INDENT (        ) @14:1> with nil
token is <Token :SSTRING (10.0.0.10:443) @14:9> with <Token :COMMA (,) @13:80>
token is <Token :WHITESPACE (               ) @14:24> with nil
token is <Token :FARROW (=>) @14:39> with <Token :SSTRING (10.0.0.10:443) @14:9>
token is <Token :WHITESPACE ( ) @14:41> with nil
token is <Token :VARIABLE (stacklb::external::params::ssl_wc_se_internal) @14:42> with <Token :FARROW (=>) @14:39>
token is <Token :COMMA (,) @14:88> with <Token :VARIABLE (stacklb::external::params::ssl_wc_se_internal) @14:42>
token is <Token :NEWLINE (
) @14:89> with nil

When the interpolated value is found, rather than discovering "${external_ip_base}.16:443" as a single token, it is broken into a DQPRE, VARIABLE, and DQPOST series of tokens, thereby breaking it up and leaving line 14's '10.0.0.10:443' statement as the longest token to align with.

This doesn't fix the issue, but identifies where it is so we can attack it.

rnelson0 added a commit that referenced this issue Jun 28, 2016
  Ensure that interpolated variable delimiters (`${}`) are not ignored when calculating alignment.
  The `--fix` function remains broken, see #424 for progress on that front.
@rnelson0 rnelson0 added this to the 2.1.0 milestone Aug 2, 2016
@rnelson0 rnelson0 modified the milestones: 3.0.0, 2.1.0 Dec 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants