Build script: unhandled errors when attempting to stop previous processes (Windows WSL)
muttoni opened this issue · comments
Describe the bug
(summarizing a DM discussion with a community member on Discord)
The npm run dev
script has a preliminary step that stops previous running processes. Certain environments like Windows WSL can use different ports (or may not be in use yet), which is causing the script to fail. The startup script should either try/catch or check for port usage first.
See here: https://github.com/onflow/kitty-items/blob/master/.ki-scripts/startup.js#L187
await stopProcess("api", [3000]);
await stopProcess("web", [3001]);
await stopProcess("dev-wallet", [8701]);
await stopProcess("emulator", [8080, 3569]);
it is not finding the ports running and throws and error when it runs the following command. killPortProcess(port)
When those lines are commented out, the user on Windows WSL is able to run the startup script successfully.
To Reproduce
Steps to reproduce the behavior:
On Windows WSL, install and run Kitty Items with npm run dev:testnet
Expected behavior
Startup script should handle and catch errors without failing
Screenshots/Logs/Output
> kitty-items@1.0.0 dev:testnet
> npx cross-env CHAIN_ENV=testnet node .ki-scripts/startup.js
:information_source: Stopping previously launched processes...
xargs -
Usage:
kill [options] <pid> [...]
Options:
<pid> [...] send signal to every <pid> listed
-<signal>, -s, --signal <signal>
specify the <signal> to be sent
-l, --list=[<signal>] list all signal names, or convert one to a name
-L, --table list all signal names in a nice table
-h, --help display this help and exit
-V, --version output version information and exit
For more details see kill(1).
node:internal/process/promises:279
triggerUncaughtException(err, true /* fromPromise */);
^
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "undefined".] {
code: 'ERR_UNHANDLED_REJECTION'
}
Environment (Optional - Version, OS, Browser, etc.)
System:
OS: Linux 5.10 Ubuntu 20.04.4 LTS (Focal Fossa)
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Memory: 4.74 GB / 6.08 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
Yarn: 1.22.5 - /mnt/c/Program Files (x86)/Yarn/bin/yarn
npm: 8.5.5 - ~/jacob-build-nft-marketplace/kitty-items/node_modules/.bin/npm
Managers:
Apt: 2.0.6 - /usr/bin/apt
Utilities:
Make: 4.2.1 - /usr/bin/make
GCC: 9.3.0 - /usr/bin/gcc
Git: 2.25.1 - /usr/bin/git
IDEs:
Nano: 4.8 - /usr/bin/nano
VSCode: 1.67.0 - /home/canedy/.vscode-server/bin/57fd6d0195bb9b9d1b49f6da5db789060795de47/bin/remote-cli/code
Vim: 8.1 - /usr/bin/vim
Languages:
Bash: 5.0.17 - /usr/bin/bash
Perl: 5.30.0 - /usr/bin/perl
Python3: 3.8.10 - /usr/bin/python3
Monorepos:
Lerna: 4.0.0
The error no longer occurs when you add these two try-catch-blocks:
1) Inside stopProcess
https://github.com/onflow/kitty-items/blob/master/.ki-scripts/startup.js#L130-L139
function stopProcess(name, port) {
return new Promise((resolve, reject) => {
pm2.stop(name, function (err, result) {
pm2.delete(name, async function () {
try {
await killPortProcess(port);
resolve();
} catch (error) {
reject(error);
}
});
});
});
}
2) Around stopProcess calls
https://github.com/onflow/kitty-items/blob/master/.ki-scripts/startup.js#L187-L190
try {
await stopProcess("api", [3000]);
await stopProcess("web", [3001]);
await stopProcess("dev-wallet", [8701]);
await stopProcess("emulator", [8080, 3569]);
} catch (error) {
console.log('There were no previous processes or the processes could not be stopped');
}