From 86f977f9bd207783d5130a4f7afb9e82af151cea Mon Sep 17 00:00:00 2001 From: Ian Scott Date: Thu, 28 Jan 2016 16:35:04 -0800 Subject: [PATCH] Handle nonexistent Xauthority file --- lib/auth.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/auth.js b/lib/auth.js index 95b948f..264a3f2 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -60,7 +60,13 @@ function readXauthority(cb) { if(err.code == 'ENOENT') { // Xming/windows uses %HOME%/Xauthority ( .Xauthority with no dot ) - try with this name filename = process.env.XAUTHORITY || path.join(homedir(), 'Xauthority'); - return fs.readFile(filename, cb); + fs.readFile(filename, function (err, data) { + if (err.code == 'ENOENT') { + cb(null, null); + } else { + cb(err); + } + }); } else { cb(err); } @@ -72,6 +78,13 @@ module.exports = function( display, host, cb ) readXauthority(function(err, data) { if(err) return cb(err); + if (!data) { + return cb(null, { + authName: '', + authData: '' + }); + } + var auth = parseXauth(data); for (var cookieNum in auth) {