Viewport-error-console.js is throwing errors when logging errors

Hey everyone,

I noticed quite an annoying bug in viewport-error-console.js that causes an error to be thrown whilst an error is being logged.

When logging an error message, the viewport error console incorrectly creates a new clickable error because of unmatched double quotes (line 111):

append(pc.string.format(’<a href="{0}{1}" target="{2} class=“code-link” id="{6}">[{3}:{4}]: {5}’, codeEditorUrl, query, target, relativeUrl, line, msg, ‘error-’ + errorCount), ‘error’);

The second argument (target="{2}) is missing a double quote, causing the HTML to not parse properly sometimes (always works fine on Safari, but occasionally errors out on Edge). Because the HTML doesn’t parse properly, the statement on line 114 fails to find the link-variable. As a result, the addEventListener-invocation is performed on undefined which causes the new error.

This situation is particularly annoying, because when using a try-catch with a console.error in the catch-block, a new error is created and thrown from the catch-block by console.error. This error propagates out of the catch-block, causing more mayhem and making the try-catch pretty useless.

I can’t currently attach a repro project, but just logging an Error-object via console.error every update should pretty quickly cause this issue to happen on Microsoft Edge. Either way, the unmatched double quote being an issue should be self evident (parsing malformed HTML leading to undefined behavior and such). I should note that the issue only happens for me after the 40th error or so (could be random), and invoking document.getElementById('error-' + errorCount); with errorCount replaced by an error count one less than the error that causes the aforementioned issue does properly return a <a href-object. Not sure why it only fails after creating a certain amount of links.

Thanks for looking into the issue!

1 Like

Hi @Valgarn,

Sorry for the late reply and many thanks for the detailed write up.

Would you care logging that issue in the editor issue tracker?

1 Like