From d805526659e114f02134d37e5476c0f9a5ceeb26 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Tue, 28 Apr 2020 12:11:18 +0100 Subject: [PATCH] fix(ngcc): provide a unique exit code for timeouts (#36838) When ngcc fails due to a timeout waiting for another process to complete, it was not failing with a unique exit code, so that it was not possible to know if the process can be restarted; compared to ngcc failing for some more fatal reason. Now if ngcc exits because of a timeout, the exit code will be 177. PR Close #36838 --- packages/compiler-cli/ngcc/main-ngcc.ts | 2 +- packages/compiler-cli/ngcc/src/constants.ts | 1 + packages/compiler-cli/ngcc/src/locking/async_locker.ts | 8 +++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/compiler-cli/ngcc/main-ngcc.ts b/packages/compiler-cli/ngcc/main-ngcc.ts index 2afc9481ab..a818b5d21e 100644 --- a/packages/compiler-cli/ngcc/main-ngcc.ts +++ b/packages/compiler-cli/ngcc/main-ngcc.ts @@ -24,7 +24,7 @@ if (require.main === module) { process.exitCode = 0; } catch (e) { console.error(e.stack || e.message); - process.exit(1); + process.exit(typeof e.code === 'number' ? e.code : 1); } })(); } diff --git a/packages/compiler-cli/ngcc/src/constants.ts b/packages/compiler-cli/ngcc/src/constants.ts index e73bb7df0f..b52410030f 100644 --- a/packages/compiler-cli/ngcc/src/constants.ts +++ b/packages/compiler-cli/ngcc/src/constants.ts @@ -7,3 +7,4 @@ */ export const IMPORT_PREFIX = 'ɵngcc'; +export const NGCC_TIMED_OUT_EXIT_CODE = 177; diff --git a/packages/compiler-cli/ngcc/src/locking/async_locker.ts b/packages/compiler-cli/ngcc/src/locking/async_locker.ts index 36a8c8faf5..4d8bcdef55 100644 --- a/packages/compiler-cli/ngcc/src/locking/async_locker.ts +++ b/packages/compiler-cli/ngcc/src/locking/async_locker.ts @@ -5,9 +5,15 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ +import {NGCC_TIMED_OUT_EXIT_CODE} from '../constants'; import {Logger} from '../logging/logger'; + import {LockFile} from './lock_file'; +class TimeoutError extends Error { + code = NGCC_TIMED_OUT_EXIT_CODE; +} + /** * AsyncLocker is used to prevent more than one instance of ngcc executing at the same time, * when being called in an asynchronous context. @@ -61,7 +67,7 @@ export class AsyncLocker { } } // If we fall out of the loop then we ran out of rety attempts - throw new Error( + throw new TimeoutError( `Timed out waiting ${ this.retryAttempts * this.retryDelay / 1000}s for another ngcc process, with id ${pid}, to complete.\n` +