Skip to content

Commit

Permalink
feat: expose remaining resources in timeout error object; implements #72
Browse files Browse the repository at this point in the history
  • Loading branch information
jmealo committed Aug 6, 2020
1 parent f0450ab commit db03720
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/wait-on.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit db03720

Please sign in to comment.