Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get original function name in AVV_ERR_READY_TIMEOUT #257

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
})