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

Change Metadata.from_file to reliably raise #503

Merged
merged 5 commits into from
May 8, 2018
Merged

Conversation

DavidS
Copy link
Contributor

@DavidS DavidS commented May 8, 2018

When no metadata.json exists, File.file? can throw nasty exceptions:

david@davids:~/git/pdk$ ./bin/pdk bundle list
Traceback (most recent call last):
	11: from ./bin/pdk:29:in `<main>'
	10: from ./bin/pdk:29:in `load'
	 9: from /home/david/git/pdk/exe/pdk:6:in `<top (required)>'
	 8: from /home/david/git/pdk/lib/pdk/cli.rb:18:in `run'
	 7: from /home/david/gems/ruby/2.5.0/gems/cri-2.10.1/lib/cri/command.rb:287:in `run'
	 6: from /home/david/gems/ruby/2.5.0/gems/cri-2.10.1/lib/cri/command.rb:269:in `run'
	 5: from /home/david/gems/ruby/2.5.0/gems/cri-2.10.1/lib/cri/command.rb:329:in `run_this'
	 4: from /home/david/git/pdk/lib/pdk/cli/bundle.rb:24:in `block (2 levels) in <module:CLI>'
	 3: from /home/david/git/pdk/lib/pdk/cli/util.rb:96:in `puppet_from_opts_or_env'
	 2: from /home/david/git/pdk/lib/pdk/util/puppet_version.rb:86:in `from_module_metadata'
	 1: from /home/david/git/pdk/lib/pdk/module/metadata.rb:48:in `from_file'
/home/david/git/pdk/lib/pdk/module/metadata.rb:48:in `file?': no implicit conversion of nil into String (TypeError)
david@davids:~/git/pdk$ 

@coveralls
Copy link

coveralls commented May 8, 2018

Coverage Status

Coverage decreased (-0.02%) to 92.844% when pulling daae6b5 on metadata-reading into 43debfc on master.

@scotje
Copy link
Contributor

scotje commented May 8, 2018

Working from direct branches seems to trigger double builds in travis/appveyor. :/

@scotje
Copy link
Contributor

scotje commented May 8, 2018

Expanded this a little bit to handle the underlying issue a bit better and make sure the error messages and warnings are useful. Also added tests.

DavidS and others added 5 commits May 8, 2018 15:17
When no `metadata.json` exists, `File.file?` can throw nasty exceptions:
```
david@davids:~/git/pdk$ ./bin/pdk bundle list
Traceback (most recent call last):
	11: from ./bin/pdk:29:in `<main>'
	10: from ./bin/pdk:29:in `load'
	 9: from /home/david/git/pdk/exe/pdk:6:in `<top (required)>'
	 8: from /home/david/git/pdk/lib/pdk/cli.rb:18:in `run'
	 7: from /home/david/gems/ruby/2.5.0/gems/cri-2.10.1/lib/cri/command.rb:287:in `run'
	 6: from /home/david/gems/ruby/2.5.0/gems/cri-2.10.1/lib/cri/command.rb:269:in `run'
	 5: from /home/david/gems/ruby/2.5.0/gems/cri-2.10.1/lib/cri/command.rb:329:in `run_this'
	 4: from /home/david/git/pdk/lib/pdk/cli/bundle.rb:24:in `block (2 levels) in <module:CLI>'
	 3: from /home/david/git/pdk/lib/pdk/cli/util.rb:96:in `puppet_from_opts_or_env'
	 2: from /home/david/git/pdk/lib/pdk/util/puppet_version.rb:86:in `from_module_metadata'
	 1: from /home/david/git/pdk/lib/pdk/module/metadata.rb:48:in `from_file'
/home/david/git/pdk/lib/pdk/module/metadata.rb:48:in `file?': no implicit conversion of nil into String (TypeError)
david@davids:~/git/pdk$ 
```
If a module doesn't have metadata.json, the .find_upwards helper will
return nil. We shouldn't send nil to the metadata helper but if we do it
should handle it more gracefully.
PDK::Util::PuppetVersion.from_module_metadata now issues a warning and
returns nil if the module does not have a metadata.json file.
The `pdk convert` acceptance tests were not specifying a --template-url
which caused them to fall back to reading whatever template-url was
specified in the users answers file, rather than the same template-url
that was used to generate the test module.

Also the tests were expecting there to be a .project file to manage but
that was recently removed from the templates.
@bmjen bmjen merged commit 78a7f0d into master May 8, 2018
@bmjen bmjen deleted the metadata-reading branch May 8, 2018 23:54
@bmjen bmjen added the bug label Jun 21, 2018
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 this pull request may close these issues.

4 participants