diff --git a/lib/Common.js b/lib/Common.js index 438628655..f5f3e9fbd 100644 --- a/lib/Common.js +++ b/lib/Common.js @@ -145,6 +145,10 @@ Common.prepareAppConf = function(opts, app) { cwd && (cwd[0] != '/') && (cwd = path.resolve(process.cwd(), cwd)); cwd = cwd || opts.cwd; + if (!fs.existsSync(cwd)) { + return new Error(`No such directory, cwd '${cwd}'`); + } + // Full path script resolution app.pm_exec_path = path.resolve(cwd, app.script); diff --git a/test/programmatic/programmatic.js b/test/programmatic/programmatic.js index 9c31109ec..2cd7fcba5 100644 --- a/test/programmatic/programmatic.js +++ b/test/programmatic/programmatic.js @@ -95,6 +95,16 @@ describe('PM2 programmatic calls', function() { }); }); + it('should throw if cwd doesn\'t exist', function(done) { + pm2.start({ + command: 'echo $PWD', + cwd: "./IMAGINARY_DIR", + }, function(err, data) { + should.exists(err); + done(); + }) + }); + it('should notice error if wrong file passed', function(done) { pm2.start('./UNKNOWN_SCRIPT.js', { force : true,