summaryrefslogtreecommitdiff
path: root/lib/chef/formatters
diff options
context:
space:
mode:
authorMartin Smith <martin@mbs3.org>2015-08-06 10:51:53 -0500
committerMartin Smith <martin@mbs3.org>2015-08-06 10:51:53 -0500
commit3060794742d90b0d8cef8f21bddce4a330b97153 (patch)
tree50d941127a52d1c5dac446038e70177cf0c22cef /lib/chef/formatters
parent3cb1dd2b59a5c2a32db24287cb8bf43b6d3357e4 (diff)
downloadchef-3060794742d90b0d8cef8f21bddce4a330b97153.tar.gz
Add additional helpful section for frozen objects
Augument runtime errors with additional information that explains why an object might be frozen, and how frozen resource properties are a good thing. Fixes #3734, for [accepted RFC 55](https://github.com/chef/chef-rfc/pull/135).
Diffstat (limited to 'lib/chef/formatters')
-rw-r--r--lib/chef/formatters/error_inspectors/compile_error_inspector.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/chef/formatters/error_inspectors/compile_error_inspector.rb b/lib/chef/formatters/error_inspectors/compile_error_inspector.rb
index d64d5e7b01..fe418ed485 100644
--- a/lib/chef/formatters/error_inspectors/compile_error_inspector.rb
+++ b/lib/chef/formatters/error_inspectors/compile_error_inspector.rb
@@ -44,6 +44,18 @@ class Chef
error_description.section("Cookbook Trace:", traceback)
error_description.section("Relevant File Content:", context)
end
+
+ if exception_message_modifying_frozen?
+ msg = <<-MESSAGE
+ Chef calls the freeze method on certain ruby objects to prevent
+ pollution across multiple instances. Specifically, resource
+ properties have frozen default values to avoid modifying the
+ property for all instances of a resource. Try modifying the
+ particular instance variable or using an instance accessor instead.
+ MESSAGE
+
+ error_description.section("Additional information:", msg.gsub(/^ {6}/, ''))
+ end
end
def context
@@ -111,6 +123,10 @@ class Chef
end
end
+ def exception_message_modifying_frozen?
+ exception.message.include?("can't modify frozen")
+ end
+
end
end