Skip to content

Commit

Permalink
Get original function name in AVV_ERR_READY_TIMEOUT (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
remidewitte authored Jun 4, 2024
1 parent ea6c932 commit 2075e4b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
6 changes: 4 additions & 2 deletions boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ function callWithCbOrNextTick (func, cb) {
}

function timeoutCall (func, rootErr, context, cb) {
const name = func.name
const name = func.unwrappedName ?? func.name
debug('setting up ready timeout', name, this._opts.timeout)
let timer = setTimeout(() => {
debug('timed out', name)
Expand Down Expand Up @@ -571,7 +571,9 @@ function encapsulateTwoParam (func, that) {
}

function encapsulateThreeParam (func, that) {
return _encapsulateThreeParam.bind(that)
const wrapped = _encapsulateThreeParam.bind(that)
wrapped.unwrappedName = func.name
return wrapped
function _encapsulateThreeParam (err, cb) {
let res
if (!func) {
Expand Down
33 changes: 33 additions & 0 deletions test/on-ready-timeout-await.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict'

/* eslint no-prototype-builtins: off */

const { test } = require('tap')
const boot = require('../boot')

test('onReadyTimeout', async (t) => {
const app = boot({}, {
timeout: 10, // 10 ms
autostart: false
})

app.use(function one (innerApp, opts, next) {
t.pass('loaded')
innerApp.ready(function readyNoResolve (err, done) {
t.notOk(err)
t.pass('first ready called')
// Do not call done() to timeout
})
next()
})

await app.start()

try {
await app.ready()
t.fail('should throw')
} catch (err) {
t.equal(err.message, 'Plugin did not start in time: \'readyNoResolve\'. You may have forgotten to call \'done\' function or to resolve a Promise')
// And not Plugin did not start in time: 'bound _encapsulateThreeParam'. You may have forgotten to call 'done' function or to resolve a Promise
}
})

0 comments on commit 2075e4b

Please sign in to comment.