From 1698b7384177ca40c038af36c3c05e504fdaff06 Mon Sep 17 00:00:00 2001 From: Joran Dirk Greef Date: Mon, 7 Sep 2015 08:51:03 +0200 Subject: [PATCH] Fix early error check skipping password prompt --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index e23da45..d7cf05b 100644 --- a/index.js +++ b/index.js @@ -29,17 +29,17 @@ Sudo.Mac = function(command, end, count) { // Run sudo in non-interactive mode (-n). Node.child.exec('sudo -n ' + command, function(error, stdout, stderr) { - if (error) return end(error); - if (stderr !== 'sudo: a password is required\n') { - if (/^sudo:/i.test(stderr)) return end(stderr); - end(error, stdout, stderr); - } else { + if (/sudo: a password is required/i.test(stderr)) { Sudo.Mac.prompt( function(error) { if (error) return end(error); Sudo.Mac(command, end, ++count); // Cannot use ++ suffix here. } ); + } else if (!error && /^sudo:/i.test(stderr)) { + end('Unexpected stderr from sudo command without corresponding error: ' + stderr); + } else { + end(error, stdout, stderr); } } );