From db03720f5b96049fc175307428dae44996abdcf5 Mon Sep 17 00:00:00 2001 From: Jeff Mealo Date: Wed, 5 Aug 2020 20:10:42 -0400 Subject: [PATCH] feat: expose remaining resources in timeout error object; implements #72 --- lib/wait-on.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/wait-on.js b/lib/wait-on.js index ea09ec1..a154ced 100644 --- a/lib/wait-on.js +++ b/lib/wait-on.js @@ -22,7 +22,7 @@ const PREFIX_RE = /^((https?-get|https?|tcp|socket|file):)(.+)$/; const HOST_PORT_RE = /^(([^:]*):)?(\d+)$/; const HTTP_GET_RE = /^https?-get:/; const HTTP_UNIX_RE = /^http:\/\/unix:([^:]+):([^:]+)$/; -const TIMEOUT_ERR_MSG = 'Timeout'; +const TIMEOUT_ERR_MSG = 'Timed out waiting for'; const WAIT_ON_SCHEMA = Joi.object({ resources: Joi.array().items(Joi.string().required()).required(), @@ -125,13 +125,15 @@ function waitOnImpl(opts, cbFunc) { let lastResourcesState = resources; // the last state we had recorded const timeoutError$ = - timeout !== Infinity ? timer(timeout).pipe(mergeMap(() => throwError(Error('Timeout')))) : NEVER; + timeout !== Infinity ? timer(timeout).pipe(mergeMap(() => { + const resourcesWaitingFor = determineRemainingResources(resources, lastResourcesState).join(', ') + return throwError(Error(`${TIMEOUT_ERR_MSG}: ${resourcesWaitingFor}`)) + })) : NEVER; function cleanup(err) { if (err) { - if (err.message === TIMEOUT_ERR_MSG) { - const resourcesWaitingFor = determineRemainingResources(resources, lastResourcesState).join(', '); - log('wait-on(%s) timed out waiting for: %s; exiting with error', process.pid, resourcesWaitingFor); + if (err.message.startsWith(TIMEOUT_ERR_MSG)) { + log('wait-on(%s) %s; exiting with error', process.pid, err.message); } else { log('wait-on(%s) exiting with error', process.pid, err); }