diff options
author | Noah Kantrowitz <noah@coderanger.net> | 2017-08-15 12:20:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-15 12:20:03 -0700 |
commit | f6578f1ef5ac5d18f8d0956bce46858e373b5971 (patch) | |
tree | 8e673419404a082bab47197446b9a3f334157969 | |
parent | c43ffab7a8eaf8466923a281fd746d769ef72022 (diff) | |
parent | 4639c0c67a98c0c5af1fc302ecc729aec435d452 (diff) | |
download | chef-f6578f1ef5ac5d18f8d0956bce46858e373b5971.tar.gz |
Merge pull request #6331 from coderanger/required-error
Ignore validation errors in Resource#to_text
-rw-r--r-- | lib/chef/resource.rb | 6 | ||||
-rw-r--r-- | spec/unit/resource_spec.rb | 8 |
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index ca6603c06a..5436e3ceb3 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -641,7 +641,11 @@ class Chef all_props = {} self.class.state_properties.map do |p| - all_props[p.name.to_s] = p.sensitive? ? '"*sensitive value suppressed*"' : value_to_text(p.get(self)) + begin + all_props[p.name.to_s] = p.sensitive? ? '"*sensitive value suppressed*"' : value_to_text(p.get(self)) + rescue Chef::Exceptions::ValidationFailed + # This space left intentionally blank, the property was probably required or had an invalid default. + end end ivars = instance_variables.map { |ivar| ivar.to_sym } - HIDDEN_IVARS diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index 6285bad50a..9227c8b12d 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -377,6 +377,14 @@ describe Chef::Resource do expect(resource.to_text).to match(/foo "\*sensitive value suppressed\*"/) end end + + context "when property is required" do + it "does not propagate vailidation errors" do + resource_class = Class.new(Chef::Resource) { property :foo, String, required: true } + resource = resource_class.new("required_property_tests") + expect { resource.to_text }.to_not raise_error Chef::Exceptions::ValidationFailed + end + end end describe "self.resource_name" do |