philmasterplus
Active member
With JavaScript, we can now throw exception objects with arbitrary messages. If these error messages contain text that can be interpreted as HTML, the error message shown in the gCLI is rendered as such. This makes it hard to debug JavaScript errors.
For example, suppose the following code is executed:
Currently (r20608) this will be printed as:
From the stack trace alone, it is impossible to distinguish a
This problem can be exacerbated when the error message contains large HTML markup, e.g. tables. KoLmafia will try to render such messages in the gCLI instead of just printing their output.
To fix this, I suggest making
Here's a patch that applies the suggested change.
For example, suppose the following code is executed:
JavaScript:
throw new Error('<span><span> is invalid');
Currently (r20608) this will be printed as:
Code:
JavaScript exception: Error: is invalid (file:/C:/Users/Phil/Documents/KoL/scripts/test.js#1)
at file:/C:/Users/Phil/Documents/KoL/scripts/test.js:1
From the stack trace alone, it is impossible to distinguish a
<span>
tag from an empty string.This problem can be exacerbated when the error message contains large HTML markup, e.g. tables. KoLmafia will try to render such messages in the gCLI instead of just printing their output.
To fix this, I suggest making
KoLmafia.updateDisplay()
escape HTML in messages before it passes them to RequestLogger.printLine()
. This is preferable since we only want to escape messages sent to the gCLI. If we escaped the string before passing it it to updateDisplay()
, it would also affect messages going to other outlets, such as system tray messages (do we still use those, BTW?). As a bonus, we can now safely use characters like "<" when directly calling KoLmafia.updateDisplay()
.Here's a patch that applies the suggested change.