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

Getting 'ArgumentError: invalid byte sequence in UTF-8' when using ghostbuster_facts #63

Closed
Sher-Chowdhury opened this issue Oct 6, 2017 · 2 comments · Fixed by #84
Closed
Labels

Comments

@Sher-Chowdhury
Copy link
Contributor

Hello

I came across the following error when using ghostbuster_facts:

PUPPETDB_URL='http://localhost:8080/' HIERA_YAML_PATH='/tmp/hiera.yaml' find . -type f -
exec puppet-lint --only-checks ghostbuster_facts {} \+
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: 2.3.3
ruby version: 2.1.9-p490
platform: x86_64-darwin16.0
file path: ./modules/apt/lib/facter/apt_updates.rb
file contents:

apt_package_updates = nil
Facter.add("apt_has_updates") do
  confine :osfamily => 'Debian'
  if File.executable?("/usr/bin/apt-get")
    apt_get_result = Facter::Util::Resolution.exec('/usr/bin/apt-get -s upgrade 2>&1')
    if not apt_get_result.nil?
      apt_package_updates = [[], []]
      apt_get_result.each_line do |line|
        if line =~ /^Inst\s/
          package = line.gsub(/^Inst\s([^\s]+)\s.*/, '\1').strip
          apt_package_updates[0].push(package)
          security_matches = [
            / Debian[^\s]+-updates /,
            / Debian-Security:/,
            / Ubuntu[^\s]+-security /,
            / gNewSense[^\s]+-security /
          ]
          re = Regexp.union(security_matches)
          if line.match(re)
            apt_package_updates[1].push(package)
          end
        end
      end
    end
  end

  setcode do
    if not apt_package_updates.nil? and apt_package_updates.length == 2
      apt_package_updates != [[], []]
    end
  end
end

Facter.add("apt_package_updates") do
  confine :apt_has_updates => true
  setcode do
    if Facter.version < '2.0.0'
      apt_package_updates[0].join(',')
    else
      apt_package_updates[0]
    end
  end
end

Facter.add("apt_updates") do
  confine :apt_has_updates => true
  setcode do
    Integer(apt_package_updates[0].length)
  end
end

Facter.add("apt_security_updates") do
  confine :apt_has_updates => true
  setcode do
    Integer(apt_package_updates[1].length)
  end
end

error:

ArgumentError: invalid byte sequence in UTF-8
/Users/schowdhury/.rvm/gems/ruby-2.1.9/gems/puppet-ghostbuster-0.9.0/lib/puppet-lint/plugins/check_ghostbuster_facts.rb:40:in `==='
/Users/schowdhury/.rvm/gems/ruby-2.1.9/gems/puppet-ghostbuster-0.9.0/lib/puppet-lint/plugins/check_ghostbuster_facts.rb:40:in `each'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/gems/puppet-ghostbuster-0.9.0/lib/puppet-lint/plugins/check_ghostbuster_facts.rb:40:in `grep'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/gems/puppet-ghostbuster-0.9.0/lib/puppet-lint/plugins/check_ghostbuster_facts.rb:40:in `block (2 levels) in check'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/gems/puppet-ghostbuster-0.9.0/lib/puppet-lint/plugins/check_ghostbuster_facts.rb:39:in `each'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/gems/puppet-ghostbuster-0.9.0/lib/puppet-lint/plugins/check_ghostbuster_facts.rb:39:in `block in check'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/gems/puppet-ghostbuster-0.9.0/lib/puppet-lint/plugins/check_ghostbuster_facts.rb:28:in `each'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/gems/puppet-ghostbuster-0.9.0/lib/puppet-lint/plugins/check_ghostbuster_facts.rb:28:in `check'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/gems/puppet-lint-2.3.3/lib/puppet-lint/checkplugin.rb:21:in `run'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/gems/puppet-lint-2.3.3/lib/puppet-lint/checks.rb:60:in `block in run'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/gems/puppet-lint-2.3.3/lib/puppet-lint/checks.rb:57:in `each'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/gems/puppet-lint-2.3.3/lib/puppet-lint/checks.rb:57:in `run'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/gems/puppet-lint-2.3.3/lib/puppet-lint.rb:196:in `run'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/gems/puppet-lint-2.3.3/lib/puppet-lint/bin.rb:59:in `block in run'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/gems/puppet-lint-2.3.3/lib/puppet-lint/bin.rb:56:in `each'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/gems/puppet-lint-2.3.3/lib/puppet-lint/bin.rb:56:in `run'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/gems/puppet-lint-2.3.3/bin/puppet-lint:7:in `<top (required)>'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/bin/puppet-lint:23:in `load'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/bin/puppet-lint:23:in `<main>'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/bin/ruby_executable_hooks:15:in `eval'
/Users/schowdhury/.rvm/gems/ruby-2.1.9/bin/ruby_executable_hooks:15:in `<main>'

Here are the gem's I currently have loaded:

gem list

*** LOCAL GEMS ***

bigdecimal (default: 1.2.4)
bundler-unload (1.0.2)
CFPropertyList (2.3.5)
executable-hooks (1.3.2)
facter (2.5.1 universal-darwin)
fast_gettext (1.1.0)
gem-wrappers (1.3.2)
gettext (3.2.4)
gettext-setup (0.28)
hiera (3.4.2)
httparty (0.15.6)
io-console (default: 0.4.3)
json (default: 1.8.1)
locale (2.1.2)
minitest (default: 4.7.5)
multi_xml (0.6.0)
psych (default: 2.0.5)
puppet (5.3.2 universal-darwin)
puppet-ghostbuster (0.9.0)
puppet-lint (2.3.3)
puppetdb-ruby (1.1.1)
rake (default: 10.1.0)
rdoc (default: 4.1.0)
rubygems-bundler (1.4.4)
rvm (1.11.3.9)
test-unit (default: 2.1.9.0)
text (1.3.1)

Has anyone else came across this issue as well?

@hejdajan
Copy link

I have the same issue. Is there any update on this?

@h0tw1r3
Copy link
Contributor

h0tw1r3 commented Jan 19, 2024

Same parsing two different template files. Confirmed there are no invalid UTF-8 characters.

h0tw1r3 added a commit to h0tw1r3/puppet-ghostbuster that referenced this issue Jan 19, 2024
* read file by line until match
* only read files once per check
* prefer include over match

replacing readlines.grep happens to fix voxpupuli#63
@h0tw1r3 h0tw1r3 mentioned this issue Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants