summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKazuhiro Yamada <yamadakazu45@gmail.com>2013-07-24 21:59:28 +0900
committerJohn Keiser <jkeiser@opscode.com>2013-09-12 23:10:55 -0700
commita3ced11def5e270b1d58787992bb2cff9d889327 (patch)
treead0d9b9e05d40a700589d6877a89afcc2730a6f9 /lib
parent544e9e3a8f67abbec77da8d8a857c7845c8b6444 (diff)
downloadchef-a3ced11def5e270b1d58787992bb2cff9d889327.tar.gz
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"]}
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/chef_fs/file_system.rb13
1 files changed, 12 insertions, 1 deletions
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?