diff options
author | Stuart Preston <stuart@chef.io> | 2018-07-17 17:07:39 +0100 |
---|---|---|
committer | Stuart Preston <stuart@chef.io> | 2018-07-17 17:07:39 +0100 |
commit | 9a2b93d63a0084d738137579e64604d425940938 (patch) | |
tree | 5f5143640c9b2bca18d12832b1bba8c9df5a4851 | |
parent | 8fa394155c5305f676adfcd27e864bb82efa62ed (diff) | |
download | chef-9a2b93d63a0084d738137579e64604d425940938.tar.gz |
Reverting addition of code to Win32APIError
Signed-off-by: Stuart Preston <stuart@chef.io>
-rw-r--r-- | lib/chef/exceptions.rb | 11 | ||||
-rw-r--r-- | lib/chef/util/windows/net_user.rb | 2 | ||||
-rw-r--r-- | lib/chef/win32/error.rb | 2 | ||||
-rw-r--r-- | spec/unit/win32/error_spec.rb | 8 |
4 files changed, 6 insertions, 17 deletions
diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb index cb82f403e9..ca388d33cd 100644 --- a/lib/chef/exceptions.rb +++ b/lib/chef/exceptions.rb @@ -148,16 +148,7 @@ class Chef class InvalidDataBagName < ArgumentError; end class EnclosingDirectoryDoesNotExist < ArgumentError; end # Errors originating from calls to the Win32 API - class Win32APIError < RuntimeError - attr_reader :code - def initialize(msg, error_code = -1) - @code = error_code - super(msg) - end - def initialize - super - end - end + class Win32APIError < RuntimeError; 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. diff --git a/lib/chef/util/windows/net_user.rb b/lib/chef/util/windows/net_user.rb index d465702834..25a413861b 100644 --- a/lib/chef/util/windows/net_user.rb +++ b/lib/chef/util/windows/net_user.rb @@ -99,7 +99,7 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows true rescue Chef::Exceptions::Win32APIError => e # we're only interested in the password failures - if e.code == Win32APIError::ERROR_LOGON_FAILURE + if FFI::LastError.error == Win32APIError::ERROR_LOGON_FAILURE return false end # all other exceptions will assume we cannot logon for a different reason diff --git a/lib/chef/win32/error.rb b/lib/chef/win32/error.rb index e806488b33..83d4583f1d 100644 --- a/lib/chef/win32/error.rb +++ b/lib/chef/win32/error.rb @@ -78,7 +78,7 @@ class Chef formatted_message << "System Error Code: #{code}\n" formatted_message << "System Error Message: #{msg}\n" formatted_message << "---- End Win32 API output ----\n" - raise Chef::Exceptions::Win32APIError.new(msg + "\n" + formatted_message, code) + raise Chef::Exceptions::Win32APIError, msg + "\n" + formatted_message end end end diff --git a/spec/unit/win32/error_spec.rb b/spec/unit/win32/error_spec.rb index 914c433629..316303ab4f 100644 --- a/spec/unit/win32/error_spec.rb +++ b/spec/unit/win32/error_spec.rb @@ -41,10 +41,7 @@ describe "Chef::Win32::Error", :windows_only do Chef::ReservedNames::Win32::API::Error::ERROR_BAD_USERNAME ) expect(Chef::ReservedNames::Win32::Error).to receive_message_chain(:format_message, :strip).and_return("Bad Username") - expect { Chef::ReservedNames::Win32::Error.raise! }.to raise_error { |error| - expect(error).to be_a(Chef::Exceptions::Win32APIError) - expect(error.code).to eq(2202) - } + expect { Chef::ReservedNames::Win32::Error.raise! }.to raise_error(Chef::Exceptions::Win32APIError) end end end @@ -70,7 +67,8 @@ describe "Chef::Win32::Error", :windows_only do it "raises a Win32ApiError exception with code 1326" do expect { Chef::ReservedNames::Win32::Error.raise! nil, Chef::ReservedNames::Win32::API::Error::ERROR_LOGON_FAILURE }.to raise_error { |error| expect(error).to be_a(Chef::Exceptions::Win32APIError) - expect(error.code).to eq(1326) + # This is not localized but neither is the exception. + expect(error.to_s).to match(/System Error Code: 1326/) } end end |