Skip to content
This repository was archived by the owner on Jul 14, 2021. It is now read-only.

Better error messaging when license is invalid #1180

Merged
merged 2 commits into from
Mar 1, 2017

Conversation

tduffield
Copy link
Contributor

Description

Rebase of #984

Issues Resolved

Fixes #983

Check List

This allows someone setting an invalid license parameter on the generator to receive an error and give a location to find valid values.

I didn't find a good reference for the generator settings and when entering 'none' based on the config.rb talk it causes an undefined method error due to result not having a value.

related docs:
https://docs.chef.io/config_rb.html  (shows none albeit for a different setting)
https://docs.chef.io/ctl_chef.html#chef-generate-cookbook  (shows all_rights as the default)

Command output before change:
```
C:\Users\slarson\cookbooks
λ chef generate cookbook dt_test
Generating cookbook dt_test
- Ensuring correct cookbook file content

================================================================================
Error executing action `create_if_missing` on resource 'template[C:/Users/slarson/cookbooks/dt_test/spec/unit/recipes/default_spec.rb]'
================================================================================

Chef::Mixin::Template::TemplateError
------------------------------------
undefined method `gsub' for nil:NilClass

Resource Declaration:
---------------------

 84: template "#{cookbook_dir}/spec/unit/recipes/default_spec.rb" do
 85:   source "recipe_spec.rb.erb"
 86:   helpers(ChefDK::Generator::TemplateHelper)
 87:   action :create_if_missing
 88: end
 89:

Compiled Resource:
------------------

template("C:/Users/slarson/cookbooks/dt_test/spec/unit/recipes/default_spec.rb") do
  action [:create_if_missing]
  retries 0
  retry_delay 2
  default_guard_interpreter :default
  source "recipe_spec.rb.erb"
  helper_modules [ChefDK::Generator::TemplateHelper]
  declared_type :template
  cookbook_name :dt_generator
  recipe_name "cookbook"
  path "C:/Users/slarson/cookbooks/dt_test/spec/unit/recipes/default_spec.rb"
end

Template Context:
-----------------
on line #5
  3: # Spec:: default
  4: #
  5: <%= license_description('#') %>
  6:
  7: require 'spec_helper'

Platform:
---------
i386-mingw32

ERROR: Chef failed to converge:

Chef::Mixin::Template::TemplateError (undefined method `gsub' for nil:NilClass) on line #5:

  3: # Spec:: default
  4: #
  5: <%= license_description('#') %>
  6:
  7: require 'spec_helper'

  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-dk-0.16.28/lib/chef-dk/generator.rb:155:in `license_description'
  (erubis):5:in `block in evaluate'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/erubis-2.7.0/lib/erubis/evaluator.rb:74:in `instance_eval'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/erubis-2.7.0/lib/erubis/evaluator.rb:74:in `evaluate'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/mixin/template.rb:161:in`_render_templat
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/mixin/template.rb:147:in`render_template
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/provider/template/content.rb:53:in `file_
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/file_content_management/content_base.rb:4
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/provider/file.rb:462:in `tempfile'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/provider/file.rb:339:in`do_generate_cont
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/provider/file.rb:150:in`action_create'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/provider/file.rb:162:in`action_create_if
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/provider.rb:145:in `run_action'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/resource.rb:591:in `run_action'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/runner.rb:69:in `run_action'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/runner.rb:97:in `block (2 levels) in conv
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/runner.rb:97:in `each'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/runner.rb:97:in `block in converge'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/resource_collection/resource_list.rb:94:ie_each_resource'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:tor_block'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:ndex'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/resource_collection/resource_list.rb:92:isource'
  C:/opscode/chefdk/embedded/lib/ruby/2.1.0/forwardable.rb:183:in `execute_each_resource'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/runner.rb:96:in `converge'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-dk-0.16.28/lib/chef-dk/chef_runner.rb:43:in `converge'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-dk-0.16.28/lib/chef-dk/command/generator_commands/cookbook.rb:82:in`run'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-dk-0.16.28/lib/chef-dk/command/generate.rb:88:in `run'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-dk-0.16.28/lib/chef-dk/command/base.rb:58:in`run_with_default_options'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-dk-0.16.28/lib/chef-dk/cli.rb:73:in `run'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-dk-0.16.28/bin/chef:25:in `<top (required)>'
  C:/opscode/chefdk/bin/chef:85:in `load'
  C:/opscode/chefdk/bin/chef:85:in `<main>'

Caused by: (Chef::Mixin::Template::TemplateError) undefined method `gsub' for nil:NilClass
```

Output after:
C:\Users\slarson\cookbooks
λ rm -rf dt_test\

C:\Users\slarson\cookbooks
λ chef generate cookbook dt_test
Generating cookbook dt_test
- Ensuring correct cookbook file content

================================================================================
Error executing action `create_if_missing` on resource 'template[C:/Users/slarson/cookbooks/dt_test/spec/unit/recipes/default_spec.rb]'
================================================================================

Chef::Mixin::Template::TemplateError
------------------------------------
Invalid generator.license setting: none.  See available licenses at https://docs.chef.io/ctl_chef.html#chef-generate-cookbook

Resource Declaration:
---------------------

 84: template "#{cookbook_dir}/spec/unit/recipes/default_spec.rb" do
 85:   source "recipe_spec.rb.erb"
 86:   helpers(ChefDK::Generator::TemplateHelper)
 87:   action :create_if_missing
 88: end
 89:

Compiled Resource:
------------------

template("C:/Users/slarson/cookbooks/dt_test/spec/unit/recipes/default_spec.rb") do
  action [:create_if_missing]
  retries 0
  retry_delay 2
  default_guard_interpreter :default
  source "recipe_spec.rb.erb"
  helper_modules [ChefDK::Generator::TemplateHelper]
  declared_type :template
  cookbook_name :dt_generator
  recipe_name "cookbook"
  path "C:/Users/slarson/cookbooks/dt_test/spec/unit/recipes/default_spec.rb"
end

Template Context:
-----------------
on line #5
  3: # Spec:: default
  4: #
  5: <%= license_description('#') %>
  6:
  7: require 'spec_helper'

Platform:
---------
i386-mingw32

ERROR: Chef failed to converge:

Chef::Mixin::Template::TemplateError (Invalid generator.license setting: none.  See available licenses at https://docs.chef.io/ctl_chef.html#chef-generate-cookbook) on line #5:

  3: # Spec:: default
  4: #
  5: <%= license_description('#') %>
  6:
  7: require 'spec_helper'

  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-dk-0.16.28/lib/chef-dk/generator.rb:153:in `license_description'
  (erubis):5:in `block in evaluate'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/erubis-2.7.0/lib/erubis/evaluator.rb:74:in `instance_eval'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/erubis-2.7.0/lib/erubis/evaluator.rb:74:in `evaluate'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/mixin/template.rb:161:in `_render_template'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/mixin/template.rb:147:in `render_template'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/provider/template/content.rb:53:in `file_for_provider'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/file_content_management/content_base.rb:40:in `tempfile'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/provider/file.rb:462:in`tempfile'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/provider/file.rb:339:in`do_generate_content'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/provider/file.rb:150:in`action_create'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/provider/file.rb:162:in`action_create_if_missing'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/provider.rb:145:in`run_action'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/resource.rb:591:in`run_action'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/runner.rb:69:in`run_action'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/runner.rb:97:in `block (2 levels) in converge'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/runner.rb:97:in `each'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/runner.rb:97:in `block in converge'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/resource_collection/resource_list.rb:94:in `block in execute_each_resource'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:116:in `call'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/resource_collection/resource_list.rb:92:in `execute_each_resource'
  C:/opscode/chefdk/embedded/lib/ruby/2.1.0/forwardable.rb:183:in `execute_each_resource'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.12.15-universal-mingw32/lib/chef/runner.rb:96:in `converge'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-dk-0.16.28/lib/chef-dk/chef_runner.rb:43:in `converge'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-dk-0.16.28/lib/chef-dk/command/generator_commands/cookbook.rb:82:in`run'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-dk-0.16.28/lib/chef-dk/command/generate.rb:88:in`run'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-dk-0.16.28/lib/chef-dk/command/base.rb:58:in`run_with_default_options'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-dk-0.16.28/lib/chef-dk/cli.rb:73:in`run'
  C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-dk-0.16.28/bin/chef:25:in `<top(required)>'
  C:/opscode/chefdk/bin/chef:85:in `load'
  C:/opscode/chefdk/bin/chef:85:in `<main>'

Caused by: (Chef::Mixin::Template::TemplateError) Invalid generator.license setting: none.  See available licenses at https://docs.chef.io/ctl_chef.html#chef-generate-cookbook
```
@tduffield tduffield changed the title Sclarson add license error for invalid licenses Better error messaging when license is invalid Mar 1, 2017
…ub.com/sclarson/chef-dk into sclarson-add-license-error-for-invalid-licenses

Signed-off-by: Tom Duffield <tom@chef.io>
@tduffield tduffield force-pushed the sclarson-add-license-error-for-invalid-licenses branch from e27ffac to 56c0f1e Compare March 1, 2017 15:46
@tduffield tduffield merged commit 982ab38 into master Mar 1, 2017
@tduffield tduffield deleted the sclarson-add-license-error-for-invalid-licenses branch March 1, 2017 22:33
@chef-boneyard chef-boneyard locked and limited conversation to collaborators Feb 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Poor error message using generate cookbook and license settings from knife.rb
3 participants