League-of-Foundry-Developers / fvtt-module-furnace

34 stars 12 forks source link

FurnacePatching.patchFunction causing problems #74

Closed wesbaker closed 3 years ago

wesbaker commented 3 years ago

https://github.com/kakaroto/fvtt-module-furnace/blob/67d7252ad30b8c4ac9dfec195b96def2de09a19d/Macros/Macros.js#L21

Hey there, this call is causing an error in the console:

Patches.js:1 Uncaught TypeError: Cannot read property 'trim' of undefined at Function.patchClass (Patches.js:1) at Function.patchFunction (Patches.js:5) at new FurnaceMacros (Macros.js:5) at Macros.js:82

I just fixed something similar with Easy Target and looking at your code, something similar is happening. When you split the lines it's only finding one \n and then you're looking for a line_number that doesn't exist. This happens with or without minified JavaScript, so I suspect it's the internal code changing.

My recommendation would be to look at my PR to the code above and change how you're splitting code. I could also take a crack at it, but it'll be in a while.

kakaroto commented 3 years ago

Thanks! I've fixed the crash from my side and added the check for splitChar, though I'm not sure if it would work quite well since I use strict line comparison for my patching rather than an 'includes' and so some of the lines being patched include a ; in them, so they wouldn't match anymore if the split happens on ;. At least, the trim of undefined error should be gone now.

teo-cay commented 3 years ago

Hello! I'm still seeing this error in the console.

Patches.js:10 Uncaught TypeError: Cannot read property 'trim' of undefined at Function.patchClass (Patches.js:10) at Function.patchFunction (Patches.js:11) at new FurnaceMacros (Macros.js:5) at Macros.js:82

I believe I have the updated code if this was fixed in version 2.5

kakaroto commented 3 years ago

Humm.. it seems to happen in the else portion when it tries to print a console log about not finding a line. I need to make that part more robust too. Thanks.