summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorjkeiser <jkeiser@opscode.com>2013-01-20 14:33:14 -0800
committerJohn Keiser <jkeiser@opscode.com>2013-06-07 13:12:25 -0700
commit60cdaa1ec495f156b8424e094cc28bbc73c5768a (patch)
treeea2598e1f871424ad15d05032acad8b67f7e5812 /lib/chef
parent79557d0b72fd0cc91015de2a0ad016c09759084b (diff)
downloadchef-60cdaa1ec495f156b8424e094cc28bbc73c5768a.tar.gz
Print error for bad json in knife upload
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/chef_fs/file_system.rb4
-rw-r--r--lib/chef/chef_fs/file_system/file_system_error.rb4
-rw-r--r--lib/chef/chef_fs/file_system/must_delete_recursively_error.rb5
-rw-r--r--lib/chef/chef_fs/file_system/not_found_error.rb5
-rw-r--r--lib/chef/chef_fs/file_system/operation_failed_error.rb34
-rw-r--r--lib/chef/chef_fs/file_system/operation_not_allowed_error.rb3
-rw-r--r--lib/chef/chef_fs/file_system/rest_list_entry.rb18
7 files changed, 56 insertions, 17 deletions
diff --git a/lib/chef/chef_fs/file_system.rb b/lib/chef/chef_fs/file_system.rb
index 8f7bd38168..8ab9a7ceda 100644
--- a/lib/chef/chef_fs/file_system.rb
+++ b/lib/chef/chef_fs/file_system.rb
@@ -18,6 +18,7 @@
require 'chef/chef_fs/path_utils'
require 'chef/chef_fs/file_system/default_environment_cannot_be_modified_error'
+require 'chef/chef_fs/file_system/operation_failed_error'
require 'chef/chef_fs/file_system/operation_not_allowed_error'
class Chef
@@ -351,6 +352,9 @@ class Chef
end
rescue DefaultEnvironmentCannotBeModifiedError => e
ui.warn "#{format_path.call(e.entry)} #{e.reason}."
+ rescue OperationFailedError => e
+ ui.error "#{format_path.call(e.entry)} failed to #{e.operation}: #{e.message}"
+ error = true
rescue OperationNotAllowedError => e
ui.error "#{format_path.call(e.entry)} #{e.reason}."
error = true
diff --git a/lib/chef/chef_fs/file_system/file_system_error.rb b/lib/chef/chef_fs/file_system/file_system_error.rb
index a461221108..80aff35893 100644
--- a/lib/chef/chef_fs/file_system/file_system_error.rb
+++ b/lib/chef/chef_fs/file_system/file_system_error.rb
@@ -20,10 +20,12 @@ class Chef
module ChefFS
module FileSystem
class FileSystemError < StandardError
- def initialize(cause = nil)
+ def initialize(entry, cause = nil)
+ @entry = entry
@cause = cause
end
+ attr_reader :entry
attr_reader :cause
end
end
diff --git a/lib/chef/chef_fs/file_system/must_delete_recursively_error.rb b/lib/chef/chef_fs/file_system/must_delete_recursively_error.rb
index c2d003e865..bfa8ba28ce 100644
--- a/lib/chef/chef_fs/file_system/must_delete_recursively_error.rb
+++ b/lib/chef/chef_fs/file_system/must_delete_recursively_error.rb
@@ -23,11 +23,8 @@ class Chef
module FileSystem
class MustDeleteRecursivelyError < FileSystemError
def initialize(entry, cause = nil)
- super(cause)
- @entry = entry
+ super(entry, cause)
end
-
- attr_reader :entry
end
end
end
diff --git a/lib/chef/chef_fs/file_system/not_found_error.rb b/lib/chef/chef_fs/file_system/not_found_error.rb
index 14acf4259e..9eab3d6131 100644
--- a/lib/chef/chef_fs/file_system/not_found_error.rb
+++ b/lib/chef/chef_fs/file_system/not_found_error.rb
@@ -23,11 +23,8 @@ class Chef
module FileSystem
class NotFoundError < FileSystemError
def initialize(entry, cause = nil)
- super(cause)
- @entry = entry
+ super(entry, cause)
end
-
- attr_reader :entry
end
end
end
diff --git a/lib/chef/chef_fs/file_system/operation_failed_error.rb b/lib/chef/chef_fs/file_system/operation_failed_error.rb
new file mode 100644
index 0000000000..1af2d2dcff
--- /dev/null
+++ b/lib/chef/chef_fs/file_system/operation_failed_error.rb
@@ -0,0 +1,34 @@
+#
+# Author:: John Keiser (<jkeiser@opscode.com>)
+# Copyright:: Copyright (c) 2012 Opscode, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'chef/chef_fs/file_system/file_system_error'
+
+class Chef
+ module ChefFS
+ module FileSystem
+ class OperationFailedError < FileSystemError
+ def initialize(operation, entry, cause = nil)
+ super(entry, cause)
+ @operation = operation
+ end
+
+ attr_reader :operation
+ end
+ end
+ end
+end
diff --git a/lib/chef/chef_fs/file_system/operation_not_allowed_error.rb b/lib/chef/chef_fs/file_system/operation_not_allowed_error.rb
index f1e7fa8fd2..4b4f9742a8 100644
--- a/lib/chef/chef_fs/file_system/operation_not_allowed_error.rb
+++ b/lib/chef/chef_fs/file_system/operation_not_allowed_error.rb
@@ -23,9 +23,8 @@ class Chef
module FileSystem
class OperationNotAllowedError < FileSystemError
def initialize(operation, entry, cause = nil)
- super(cause)
+ super(entry, cause)
@operation = operation
- @entry = entry
end
attr_reader :operation
diff --git a/lib/chef/chef_fs/file_system/rest_list_entry.rb b/lib/chef/chef_fs/file_system/rest_list_entry.rb
index 2c8e983692..ba190f973d 100644
--- a/lib/chef/chef_fs/file_system/rest_list_entry.rb
+++ b/lib/chef/chef_fs/file_system/rest_list_entry.rb
@@ -18,6 +18,7 @@
require 'chef/chef_fs/file_system/base_fs_object'
require 'chef/chef_fs/file_system/not_found_error'
+require 'chef/chef_fs/file_system/operation_failed_error'
require 'chef/role'
require 'chef/node'
@@ -115,7 +116,7 @@ class Chef
begin
other_value = Chef::JSONCompat.from_json(other_value_json, :create_additions => false)
rescue JSON::ParserError => e
- Chef::Log.error("Parse error reading #{other.path_for_printing} as JSON: #{e}")
+ Chef::Log.warn("Parse error reading #{other.path_for_printing} as JSON: #{e}")
return [ nil, value_json, other_value_json ]
end
other_value = minimize_value(other_value)
@@ -129,18 +130,23 @@ class Chef
end
def write(file_contents)
- json = Chef::JSONCompat.from_json(file_contents).to_hash
+ begin
+ json = Chef::JSONCompat.from_json(file_contents).to_hash
+ rescue JSON::ParserError => e
+ raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e), "Parse error reading JSON: #{e}"
+ end
+
base_name = name[0,name.length-5]
if json['name'] != base_name
raise "Name in #{path_for_printing}/#{name} must be '#{base_name}' (is '#{json['name']}')"
end
begin
rest.put_rest(api_path, json)
- rescue Net::HTTPServerException
- if $!.response.code == "404"
- raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
+ rescue Net::HTTPServerException => e
+ if e.response.code == "404"
+ raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e)
else
- raise
+ raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e)
end
end
end