From 81a7d2d2796580e605efbe1ff4d3ef23fce2fa56 Mon Sep 17 00:00:00 2001 From: Colton Myers Date: Wed, 15 May 2013 14:51:43 -0600 Subject: [PATCH] Make npm.uninstall and npm.removed more consistent, Fix #4674 --- salt/modules/npm.py | 9 +++++++-- salt/states/npm.py | 16 +++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/salt/modules/npm.py b/salt/modules/npm.py index 5b5ffa3d0b..efdcf47d23 100644 --- a/salt/modules/npm.py +++ b/salt/modules/npm.py @@ -10,6 +10,8 @@ import salt.utils from salt.exceptions import CommandExecutionError +log = logging.getLogger(__name__) + def __virtual__(): ''' @@ -121,7 +123,8 @@ def uninstall(pkg, ''' if not _valid_version(): - return '"{0}" is not available.'.format('npm.uninstall') + log.error('"{0}" is not available.'.format('npm.uninstall')) + return False cmd = 'npm uninstall' @@ -133,7 +136,9 @@ def uninstall(pkg, result = __salt__['cmd.run_all'](cmd, cwd=dir, runas=runas) if result['retcode'] != 0: - raise CommandExecutionError(result['stderr']) + log.error(results['stderr']) + return False + return True def list(pkg=None, diff --git a/salt/states/npm.py b/salt/states/npm.py index 9129b347ac..002ace3b0e 100644 --- a/salt/states/npm.py +++ b/salt/states/npm.py @@ -104,13 +104,15 @@ def removed(name, ret['comment'] = 'Package {0} is set to be removed'.format(name) return ret - call = __salt__["npm.uninstall"](pkg=name, - dir=dir, - runas=runas) - - ret["result"] = True - ret["changes"][name] = "Removed" - ret["comment"] = "Package was successfully removed." + if __salt__["npm.uninstall"](pkg=name, + dir=dir, + runas=runas): + ret["result"] = True + ret["changes"][name] = 'Removed' + ret["comment"] = 'Package was successfully removed.' + else: + ret["result"] = False + ret["comment"] = 'Error removing package.' return ret