summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2014-08-22 15:31:03 -0400
committerBryan McLellan <btm@loftninjas.org>2014-08-22 19:07:23 -0400
commitec0ff9515757443b07a50a412a0a9b70a68de689 (patch)
tree3deb50d7dc540ac16a2465b6a96eb964b6585a89 /lib/chef
parentb82a5272ec6798cf26bcf9feaf39faae451b574d (diff)
downloadchef-ec0ff9515757443b07a50a412a0a9b70a68de689.tar.gz
Make exception for a user not existing more explicit
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/provider/user/windows.rb10
-rw-r--r--lib/chef/util/windows/net_user.rb6
-rw-r--r--lib/chef/win32/api/net.rb1
3 files changed, 9 insertions, 8 deletions
diff --git a/lib/chef/provider/user/windows.rb b/lib/chef/provider/user/windows.rb
index 918c598774..66ef30c349 100644
--- a/lib/chef/provider/user/windows.rb
+++ b/lib/chef/provider/user/windows.rb
@@ -17,6 +17,7 @@
#
require 'chef/provider/user'
+require 'chef/exceptions'
if RUBY_PLATFORM =~ /mswin|mingw32|windows/
require 'chef/util/windows/net_user'
end
@@ -37,17 +38,16 @@ class Chef
user_info = nil
begin
user_info = @net_user.get_info
- rescue
- @user_exists = false
- Chef::Log.debug("#{@new_resource} does not exist")
- end
- if user_info
@current_resource.uid(user_info[:user_id])
@current_resource.gid(user_info[:primary_group_id])
@current_resource.comment(user_info[:full_name])
@current_resource.home(user_info[:home_dir])
@current_resource.shell(user_info[:script_path])
+ rescue Chef::Exceptions::UserIDNotFound => e
+ # e.message should be "The user name could not be found" but checking for that could cause a localization bug
+ @user_exists = false
+ Chef::Log.debug("#{@new_resource} does not exist (#{e.message})")
end
@current_resource
diff --git a/lib/chef/util/windows/net_user.rb b/lib/chef/util/windows/net_user.rb
index 5cca348c8e..808352292e 100644
--- a/lib/chef/util/windows/net_user.rb
+++ b/lib/chef/util/windows/net_user.rb
@@ -17,6 +17,7 @@
#
require 'chef/util/windows'
+require 'chef/exceptions'
#wrapper around a subset of the NetUser* APIs.
#nothing Chef specific, but not complete enough to be its own gem, so util for now.
@@ -137,9 +138,8 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows
ptr = 0.chr * PTR_SIZE
rc = NetUserGetInfo.call(nil, @name, 3, ptr)
- if rc != NERR_Success
- raise ArgumentError, get_last_error(rc)
- end
+ raise Chef::Exceptions::UserIDNotFound, get_last_error(rc) if rc == NERR_UserNotFound
+ raise ArgumentError, get_last_error(rc) if rc != NERR_Success
ptr = ptr.unpack('L')[0]
buffer = 0.chr * SIZEOF_USER_INFO_3
diff --git a/lib/chef/win32/api/net.rb b/lib/chef/win32/api/net.rb
index cb028020cf..eeb2b078a4 100644
--- a/lib/chef/win32/api/net.rb
+++ b/lib/chef/win32/api/net.rb
@@ -33,6 +33,7 @@ class Chef
MAX_PREFERRED_LENGTH = 0xFFFF
NERR_Success = 0
+ NERR_UserNotFound = 2221
ffi_lib "netapi32"