From 6424784c19999c77228241293b018306184206f2 Mon Sep 17 00:00:00 2001 From: Edwin Date: Thu, 8 Jul 2021 16:50:40 +0530 Subject: [PATCH] Added additional logging for catching permission errors. --- lib/Local.js | 30 ++++++++++++++++++++++++++++-- lib/LocalBinary.js | 2 ++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/Local.js b/lib/Local.js index 75af73e..3d729db 100644 --- a/lib/Local.js +++ b/lib/Local.js @@ -38,14 +38,34 @@ function Local(){ that.binaryPath = binaryPath; childProcess.exec('echo "" > ' + that.logfile); + try { + if (!fs.existsSync(binaryPath)) { + console.log("Binary does not exist at ", binaryPath); + } + } catch(err) { + console.log("Failed to check the existence of Binary at ", binaryPath); + console.error(err); + } + that.opcode = 'start'; that.tunnel = childProcess.execFile(that.binaryPath, that.getBinaryArgs(), function(error, stdout, stderr){ if(error) { console.error('Error while trying to execute binary', error); + console.error('STDOUT'); + console.error(stdout); + console.error('STDERR'); + console.error(stderr); + console.error('------') if(that.retriesLeft > 0) { console.log('Retrying Binary Download. Retries Left', that.retriesLeft); that.retriesLeft -= 1; - fs.unlinkSync(that.binaryPath); + try { + fs.unlinkSync(that.binaryPath); + } catch(err) { + console.error('Failed to delete pre-existing binary: '); + console.error(err); + } + delete(that.binaryPath); that.start(options, callback); return; @@ -191,8 +211,8 @@ function Local(){ }; this.getBinaryPath = function(callback){ + this.binary = new LocalBinary(); if(typeof(this.binaryPath) == 'undefined'){ - this.binary = new LocalBinary(); var conf = {}; if(this.proxyHost && this.proxyPort){ conf.proxyHost = this.proxyHost; @@ -201,6 +221,12 @@ function Local(){ this.binary.binaryPath(conf, callback); } else { console.log('BINARY PATH IS DEFINED'); + if (this.checkPath(this.binaryPath, fs.X_OK)) { + console.log('Binary has the correct permissions.'); + } else { + console.log('Binary has incorrect permissions.'); + } + callback(this.binaryPath); } }; diff --git a/lib/LocalBinary.js b/lib/LocalBinary.js index 7e5af1e..2069d3e 100644 --- a/lib/LocalBinary.js +++ b/lib/LocalBinary.js @@ -71,6 +71,7 @@ function LocalBinary(){ }); } + console.log("Started Binary Download"); https.get(options, function (response) { response.pipe(fileStream); response.on('error', function(err) { @@ -97,6 +98,7 @@ function LocalBinary(){ var destBinaryName = (this.windows) ? 'BrowserStackLocal.exe' : 'BrowserStackLocal'; var binaryPath = path.join(destParentDir, destBinaryName); if(this.checkPath(binaryPath, fs.X_OK)){ + console.log("Binary found (with RWX flags) at ", binaryPath); callback(binaryPath); } else { this.download(conf, destParentDir, callback, 5);