Skip to content

Unexpected error when --fix against yaml with legacy fact problem #258

@cbowman0

Description

@cbowman0

Describe the Bug

When a YAML file has a legacy fact, passing --fix to puppet-lint produces an unexpected error.

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/puppetlabs/puppet-lint
and paste the following output into the issue description.

puppet-lint version: 5.1.1
ruby version: 3.3.5-p100
platform: x86_64-linux
file path: test/hiera.yaml
file contents:

---
version: 5

sample_key: host.%{::domain}

error:

NoMethodError: undefined method `value' for nil
/usr/local/share/gems/gems/puppet-lint-5.1.1/lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb:210:in `fix'
/usr/local/share/gems/gems/puppet-lint-5.1.1/lib/puppet-lint/checkplugin.rb:42:in `block in fix_problems'
/usr/local/share/gems/gems/puppet-lint-5.1.1/lib/puppet-lint/checkplugin.rb:38:in `each'
/usr/local/share/gems/gems/puppet-lint-5.1.1/lib/puppet-lint/checkplugin.rb:38:in `fix_problems'
/usr/local/share/gems/gems/puppet-lint-5.1.1/lib/puppet-lint/checks.rb:80:in `block in run'
/usr/local/share/gems/gems/puppet-lint-5.1.1/lib/puppet-lint/checks.rb:78:in `each'
/usr/local/share/gems/gems/puppet-lint-5.1.1/lib/puppet-lint/checks.rb:78:in `run'
/usr/local/share/gems/gems/puppet-lint-5.1.1/lib/puppet-lint.rb:225:in `run'
/usr/local/share/gems/gems/puppet-lint-5.1.1/lib/puppet-lint/bin.rb:88:in `block in run'
/usr/local/share/gems/gems/puppet-lint-5.1.1/lib/puppet-lint/bin.rb:83:in `each'
/usr/local/share/gems/gems/puppet-lint-5.1.1/lib/puppet-lint/bin.rb:83:in `run'
/usr/local/share/gems/gems/puppet-lint-5.1.1/bin/puppet-lint:7:in `<top (required)>'
/usr/local/bin/puppet-lint:25:in `load'
/usr/local/bin/puppet-lint:25:in `<main>'

Expected Behavior

Do not throw an error.

Steps to Reproduce

  1. Have a module with a hiera.yaml file that contains a legacy fact.
  2. Run puppet-lint --fix

Test files I was using:
test/hiera.yaml
test/files/sample.yaml
test/manifests/init.pp

hiera.yaml:

---
version: 5

sample_key: host.%{::domain}

init.pp:

# Class: test
#
class test {

  $foo = 'bar'

  $baz = 'test'

}

sample.yaml:

# This is a sample YAML file demonstrating common features

# Key-value pairs (mappings)
name: John Doe
age: 30
isStudent: false

# Lists (sequences)
hobbies:
  - Reading
  - Hiking
  - Coding

# Nested structures
address:
  street: 123 Main St
  city: Anytown
  zipCode: "12345" # String value

Environment

Version 5.1.1
Platform Rocky 9.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions