voxpupuli / librarian-puppet

MIT License
95 stars 38 forks source link

a dangling line in Puppetfile.lock will crash librarian-puppet #126

Open lelutin opened 1 month ago

lelutin commented 1 month ago

If there is any dangling dependency line in the Puppetfile.lock file, so a dependency that's not present in the Puppetfile, librarian-puppet will crash on any operation that's processing Puppetfile/Puppetfile.lock.

Here's a minimal reproducer:

Puppetfile:

forge "https://forgeapi.puppetlabs.com"

Puppetfile.lock:

DEPENDENCIES    
  LeLutin-spamassassin (= 3.2.1)    

In the above Puppetfile.lock file, there's a line for LeLutin-spamassassin but it's not present in the Puppetfile (e.g. maybe it was removed from the puppetfile but the removal was not committed to the .lock file?

This is the output that's produced by librarian-puppet:

$ librarian-puppet install --verbose
[Librarian] Ruby Version: 3.1.2
[Librarian] Ruby Platform: x86_64-linux-gnu
[Librarian] Rubygems Version: 3.4.20
[Librarian] Librarian Version: 0.6.4
[Librarian] Librarian Adapter: puppet
[Librarian] Librarian Adapter Version: 5.0.0
[Librarian] Project: /home/tor/dev/blah
[Librarian] Specfile: Puppetfile
[Librarian] Lockfile: Puppetfile.lock
[Librarian] Git: /usr/bin/git
[Librarian] Git Version: 2.45.2
[Librarian] Git Environment Variables:
[Librarian]   GIT_PS1_SHOWDIRTYSTATE=true
[Librarian]   GIT_PS1_SHOWSTASHSTATE=true
[Librarian]   GIT_PS1_SHOWUNTRACKEDFILES=true
/usr/lib/ruby/vendor_ruby/librarian/puppet/lockfile.rb:32:in `extract_and_parse_dependencies': undefined method `source' for nil:NilClass (NoMethodError)

            dependencies << environment.dsl_class.dependency_type.new(name, requirement, manifests_index[name].source, 'lockfile')
                                                                                                              ^^^^^^^
    from /usr/share/rubygems-integration/all/gems/librarianp-0.6.4/lib/librarian/lockfile/parser.rb:29:in `parse'
    from /usr/lib/ruby/vendor_ruby/librarian/puppet/lockfile.rb:73:in `load'
    from /usr/share/rubygems-integration/all/gems/librarianp-0.6.4/lib/librarian/lockfile.rb:25:in `read'
    from /usr/share/rubygems-integration/all/gems/librarianp-0.6.4/lib/librarian/action/resolve.rb:16:in `run'
    from /usr/lib/ruby/vendor_ruby/librarian/puppet/action/resolve.rb:11:in `run'
    from /usr/lib/ruby/vendor_ruby/librarian/puppet/cli.rb:111:in `resolve!'
    from /usr/lib/ruby/vendor_ruby/librarian/puppet/cli.rb:68:in `install'
    from /usr/share/rubygems-integration/all/gems/thor-1.3.1/lib/thor/command.rb:28:in `run'
    from /usr/share/rubygems-integration/all/gems/thor-1.3.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /usr/share/rubygems-integration/all/gems/thor-1.3.1/lib/thor.rb:527:in `dispatch'
    from /usr/share/rubygems-integration/all/gems/thor-1.3.1/lib/thor/base.rb:584:in `start'
    from /usr/share/rubygems-integration/all/gems/librarianp-0.6.4/lib/librarian/cli.rb:26:in `block (2 levels) in bin!'
    from /usr/share/rubygems-integration/all/gems/librarianp-0.6.4/lib/librarian/cli.rb:31:in `returning_status'
    from /usr/share/rubygems-integration/all/gems/librarianp-0.6.4/lib/librarian/cli.rb:26:in `block in bin!'
    from /usr/share/rubygems-integration/all/gems/librarianp-0.6.4/lib/librarian/cli.rb:47:in `with_environment'
    from /usr/share/rubygems-integration/all/gems/librarianp-0.6.4/lib/librarian/cli.rb:26:in `bin!'
lelutin commented 1 month ago

I think that any dependency that's in the .lock file but not present in the Puppetfile should just get dropped by librarian-puppet