Skip to content

Commit cb8a432

Browse files
committedJun 8, 2022
fix: ignore "No matching pid found" error
1 parent 50f95b3 commit cb8a432

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed
 

‎lib/resolveTaskFn.js

+23-12
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,41 @@ const handleOutput = (command, result, ctx, isError = false) => {
4646
}
4747
}
4848

49+
/**
50+
* Kill an execa process along with all its child processes.
51+
* @param {execa.ExecaChildProcess<string>} execaProcess
52+
*/
53+
const killExecaProcess = async (execaProcess) => {
54+
try {
55+
const childPids = await pidTree(execaProcess.pid)
56+
for (const childPid of childPids) {
57+
process.kill(childPid)
58+
}
59+
} catch {
60+
// Suppress "No matching pid found" error. This probably means
61+
// the process already died before executing.
62+
}
63+
64+
// The execa process is killed separately in order to get the `KILLED` status.
65+
execaProcess.kill()
66+
}
67+
4968
/**
5069
* Interrupts the execution of the execa process that we spawned if
5170
* another task adds an error to the context.
5271
*
5372
* @param {Object} ctx
5473
* @param {execa.ExecaChildProcess<string>} execaChildProcess
55-
* @returns {function(): void} Function that clears the interval that
74+
* @returns {() => void} Function that clears the interval that
5675
* checks the context.
5776
*/
5877
const interruptExecutionOnError = (ctx, execaChildProcess) => {
5978
let loopIntervalId
6079

61-
async function loop() {
80+
const loop = async () => {
6281
if (ctx.errors.size > 0) {
6382
clearInterval(loopIntervalId)
64-
65-
const childPids = await pidTree(execaChildProcess.pid)
66-
for (const pid of childPids) {
67-
process.kill(pid)
68-
}
69-
70-
// The execa process is killed separately in order
71-
// to get the `KILLED` status.
72-
execaChildProcess.kill()
83+
await killExecaProcess(execaChildProcess)
7384
}
7485
}
7586

@@ -111,7 +122,7 @@ const makeErr = (command, result, ctx) => {
111122
* @param {Array<string>} options.files — Filepaths to run the linter task against
112123
* @param {Boolean} [options.shell] — Whether to skip parsing linter task for better shell support
113124
* @param {Boolean} [options.verbose] — Always show task verbose
114-
* @returns {function(): Promise<Array<string>>}
125+
* @returns {() => Promise<Array<string>>}
115126
*/
116127
export const resolveTaskFn = ({
117128
command,

0 commit comments

Comments
 (0)
Please sign in to comment.