.catch doesn't trigger for .remote
See original GitHub issueI have an issue where I have a task to run database migrations via knex that is failing, but shipit just keeps running and never triggers the catch block.
shipit.blTask('migrations', async () => {
return shipit
.remote(`npx knex migrate:latest`, {
cwd: `${shipit.releasePath}/build`,
})
.catch(e => {
console.log(e);
process.exit();
});
});
If I console log inside .then()
I see:
[ { child: [ChildProcess],
stdout:
'\n> @ migrations:latest /var/www/api/releases/20180926144638/build\n> npx knex migrate:latest\n\nKnex:warning - migration file "20180926133945_TEST_THIS_WILL_FAIL.js" failed\nKnex:warning - migration failed with error: undefined\n',
stderr:
'Migration failed\nnpm ERR! code ELIFECYCLE\nnpm ERR! errno 1\nnpm ERR! @ migrations:latest: `npx knex migrate:latest`\nnpm ERR! Exit status 1\nnpm ERR! \nnpm ERR! Failed at the @ migrations:latest script.\nnpm ERR! This is probably not a problem with npm. There is likely additional logging output above.\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR! /home/pemmy/.npm/_logs/2018-09-26T14_47_29_617Z-debug.log\n' } ] }
ChildProcess {
_events:
{ close: [Function: exithandler],
error: [Function: errorhandler] },
_eventsCount: 2,
_maxListeners: undefined,
_closesNeeded: 3,
_closesGot: 3,
connected: false,
signalCode: null,
exitCode: 0,
...truncated
Not only does it not trigger the catch, but it shows an exit code of 0, which I assume is the exit code of the ssh command, not the command on the remote server.
The command on the remote server returns an exit code of 1.
How can I get this to trigger the .catch block so I can exit when migrations fail?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top Results From Across the Web
powershell - Try/catch does not seem to have an effect
I was able to duplicate your result when trying to run a remote WMI query. The exception thrown is not caught by the...
Read more >try catch doesn't work with Exchange cmdlets in a remote ...
Yes, I did take care to add the -ErrorAction Stop so the cmdlet should stop in case of any errors and try catch...
Read more >Linked server error not caught by TRY-CATCH
The solution is to SET XACT_ABORT ON in the calling procedure before invoking the remote procedure. When XACT_ABORT is on the CATCH block...
Read more >What TRY/CATCH Doesn't Handle - Brent Ozar Unlimited®
By having that xact_state check in the try block if somehow something does put the transaction in an uncommittable state and not trigger...
Read more >Campaign does not get triggered by RemoteAction on some ...
Hi guys, i have an issue regarding triggering campaigns via Remote Actions. We have a scheduled Remote Action, that gets automatically ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mrkrstphr As per child_process docs, the promise would be only rejected if there was some problem in the “child_process” module in not being able to start the command. If there is something wrong with the child process (in your case
npx knex migrate:latest
), it will return the error in as stderr. Inside the code make sure that, the stderr is empty string. Try the code below and it should work:-PR https://github.com/shipitjs/shipit/pull/265