Skip to content

Commit fd857fe

Browse files
committed
Build/Test Tools: Correct local environment failure handling.
Merges [63416] to the 7.1 branch. Developed in: #13354 Reviewed by: johnbillion. Props adrianmoldovanwp. See #65745. git-svn-id: https://develop.svn.wordpress.org/branches/7.1@63421 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 0d40106 commit fd857fe

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎tools/local-env/scripts/docker.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,13 @@ for ( let attempt = 1; attempt <= maxAttempts; attempt++ ) {
6060
Atomics.wait( new Int32Array( new SharedArrayBuffer( 4 ) ), 0, 0, delay * 1000 );
6161
}
6262

63-
process.exit( returns.status );
63+
if ( returns.error ) {
64+
console.error( `Could not run Docker Compose. ${ returns.error.message }` );
65+
} else if ( returns.signal && returns.signal !== 'SIGINT' ) {
66+
console.error( `Docker Compose was terminated by ${ returns.signal }.` );
67+
}
68+
69+
// `status` is null when Docker could not be spawned at all, or was killed by a signal. SIGINT is
70+
// how a long-running command such as `env:logs` is normally ended, so it is not a failure worth an
71+
// npm error block. Every other signal means the command was killed before it finished.
72+
process.exit( returns.signal === 'SIGINT' ? 0 : ( returns.status ?? 1 ) );

‎tools/local-env/scripts/start.js‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if ( process.env.LOCAL_PHP_MEMCACHED === 'true' ) {
3232
containers.push( 'memcached' );
3333
}
3434

35-
spawnSync(
35+
const up = spawnSync(
3636
'docker',
3737
[
3838
'compose',
@@ -45,6 +45,17 @@ spawnSync(
4545
{ stdio: 'inherit' }
4646
);
4747

48+
// No signal is exempt here, unlike in `docker.js`: `env:start` runs `composer update -W` next, and
49+
// that must not run against containers that never came up.
50+
if ( up.status !== 0 ) {
51+
const reason = up.signal ? `It was terminated by ${ up.signal }.` : up.error?.message ?? '';
52+
53+
console.error( `Could not start the Docker containers. ${ reason }`.trim() );
54+
55+
// `status` is null when Docker could not be spawned at all, or was killed by a signal.
56+
process.exit( up.status ?? 1 );
57+
}
58+
4859
// If Docker Toolbox is being used, we need to manually forward LOCAL_PORT to the Docker VM.
4960
if ( process.env.DOCKER_TOOLBOX_INSTALL_PATH ) {
5061
// VBoxManage is added to the PATH on every platform except Windows.

0 commit comments

Comments
 (0)