From a3ced11def5e270b1d58787992bb2cff9d889327 Mon Sep 17 00:00:00 2001 From: Kazuhiro Yamada Date: Wed, 24 Jul 2013 21:59:28 +0900 Subject: Output cause of error when FileSystem.copy_entries method was failed. - befor the change $ knife upload nodes/node.json ERROR: nodes/node.json failed to write: HTTP error writing: 400 "Bad Request" - after the change $ knife upload nodes/node.json ERROR: nodes/node.json failed to write: HTTP error writing: 400 "Bad Request" cause: {"error":["Invalid key test in request body"]} --- lib/chef/chef_fs/file_system.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/chef/chef_fs/file_system.rb b/lib/chef/chef_fs/file_system.rb index a6e14e548c..79ec09c167 100644 --- a/lib/chef/chef_fs/file_system.rb +++ b/lib/chef/chef_fs/file_system.rb @@ -394,7 +394,10 @@ class Chef rescue DefaultEnvironmentCannotBeModifiedError => e ui.warn "#{format_path.call(e.entry)} #{e.reason}." if ui rescue OperationFailedError => e - ui.error "#{format_path.call(e.entry)} failed to #{e.operation}: #{e.message}" if ui + error_msg = "#{format_path.call(e.entry)} failed to #{e.operation}: #{e.message}" + error_cause = get_error_cause(e) + error_msg += " cause: #{error_cause}" if error_cause + ui.error error_msg if ui error = true rescue OperationNotAllowedError => e ui.error "#{format_path.call(e.entry)} #{e.reason}." if ui @@ -403,6 +406,14 @@ class Chef error end + def self.get_error_cause(error) + if error.respond_to?('cause') && error.cause.instance_of?(Net::HTTPServerException) + error.cause.response.body + else + nil + end + end + def self.get_or_create_parent(entry, options, ui, format_path) parent = entry.parent if parent && !parent.exists? -- cgit v1.2.1