summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-07-29 15:38:45 -0700
committerJay Mundrawala <jdmundrawala@gmail.com>2015-07-29 15:38:45 -0700
commit3519f13ad7cb7bb582198185cb0bc470330fb866 (patch)
tree8352dd0f0b1303b6dbc7ca3ca72bb174aca48415
parent66146d5352fd59b8e1f81370e40004f423a55699 (diff)
downloadchef-3519f13ad7cb7bb582198185cb0bc470330fb866.tar.gz
Add Win32NetAPIError exception class
-rw-r--r--lib/chef/exceptions.rb17
-rw-r--r--lib/chef/util/windows/net_group.rb8
-rw-r--r--lib/chef/win32/net.rb8
3 files changed, 22 insertions, 11 deletions
diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb
index e2e36e8162..1e0b83d7b8 100644
--- a/lib/chef/exceptions.rb
+++ b/lib/chef/exceptions.rb
@@ -126,6 +126,23 @@ class Chef
class EnclosingDirectoryDoesNotExist < ArgumentError; end
# Errors originating from calls to the Win32 API
class Win32APIError < RuntimeError; end
+
+ class Win32NetAPIError < Win32APIError
+ attr_reader :msg, :error_code
+ def initialize(msg, error_code)
+ @msg = msg
+ @error_code = error_code
+
+ formatted_message = ""
+ formatted_message << "---- Begin Win32 API output ----\n"
+ formatted_message << "Net Api Error Code: #{error_code}\n"
+ formatted_message << "Net Api Error Message: #{msg}\n"
+ formatted_message << "---- End Win32 API output ----\n"
+
+ super(formatted_message)
+ end
+ end
+
# Thrown when Win32 API layer binds to non-existent Win32 function. Occurs
# when older versions of Windows don't support newer Win32 API functions.
class Win32APIFunctionNotImplemented < NotImplementedError; end
diff --git a/lib/chef/util/windows/net_group.rb b/lib/chef/util/windows/net_group.rb
index 9e7d3cbc36..30c32cbc65 100644
--- a/lib/chef/util/windows/net_group.rb
+++ b/lib/chef/util/windows/net_group.rb
@@ -83,8 +83,8 @@ class Chef::Util::Windows::NetGroup < Chef::Util::Windows
def local_add
begin
Chef::ReservedNames::Win32::NetUser::net_local_group_add(nil, @groupname)
- rescue Chef::Exceptions::Win32APIError => e
- raise ArgumentError, e
+ rescue Chef::Exceptions::Win32NetAPIError => e
+ raise ArgumentError, e.msg
end
end
@@ -103,8 +103,8 @@ class Chef::Util::Windows::NetGroup < Chef::Util::Windows
def local_delete
begin
Chef::ReservedNames::Win32::NetUser::net_local_group_del(nil, @groupname)
- rescue Chef::Exceptions::Win32APIError => e
- raise ArgumentError, e
+ rescue Chef::Exceptions::Win32NetAPIError => e
+ raise ArgumentError, e.msg
end
end
end
diff --git a/lib/chef/win32/net.rb b/lib/chef/win32/net.rb
index 29a2bb2244..18a26d92bc 100644
--- a/lib/chef/win32/net.rb
+++ b/lib/chef/win32/net.rb
@@ -97,13 +97,7 @@ END
"Received unknown error code (#{code})"
end
- formatted_message = ""
- formatted_message << "---- Begin Win32 API output ----\n"
- formatted_message << "Net Api Error Code: #{code}\n"
- formatted_message << "Net Api Error Message: #{msg}\n"
- formatted_message << "---- End Win32 API output ----\n"
-
- raise Chef::Exceptions::Win32APIError, msg + "\n" + formatted_message
+ raise Chef::Exceptions::Win32NetAPIError.new(msg, code)
end
def self.net_local_group_add(server_name, group_name)