Larkinabout / fvtt-token-action-hud-core

Token Action HUD is a repositionable HUD of actions for a selected token.
14 stars 17 forks source link

[BUG] Logger.debug() called on tokenActionHudCoreApiReady creates infinite loop. #245

Closed draconas1 closed 1 week ago

draconas1 commented 1 month ago

Describe the bug

Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
    coreModule.api.Logger.debug('badger')
}

However The debug method first makes a check for the debug variable. And int his case it is hitting the else condition so calls into Utils.getSetting('debug')

 static debug (message, data) {
        const isDebug = (game.tokenActionHud) ? game.tokenActionHud.debugSetting : Utils.getSetting('debug')

getSetting has a catch block that calls Logger.debug so if the setting is not found and the catch runs we end up in an infinite loop looking for the debug flag.

This causes an infinite loop, breaking with a stack overflow

ils.js:18 Uncaught (in promise) RangeError: undefined. Maximum call stack size exceeded
[Detected 2 packages: token-action-hud-core, foundry-4e-tools]
    at Logger.debug (utils.js:18:90)
    at Utils.getSetting (utils.js:176:20)
    at Logger.debug (utils.js:18:90)
    at Utils.getSetting (utils.js:176:20)
    at Logger.debug (utils.js:18:90)

Steps to reproduce Creating a sample hook listener that immediately calls debug should do the trick.

Versions:

Additional context Any additional context.

draconas1 commented 1 month ago

Interestingly I have debug enabled on this, so am unsure why it was hitting the catch block and getting the infinite loop.

Larkinabout commented 1 week ago

Fixed in Token Action HUD Core 1.5.6.