Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 10 additions & 0 deletions test/programmatic/programmatic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down