Exception message for assert(0) depends on whitespaceΒ #30872
Description
Activity
- addedassertIssues and PRs related to the assert subsystem.Issues and PRs related to the assert subsystem.confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Dec 9, 2019 @AndrewFinlay thank you for the report. This should indeed not fail to create the better error message.
The left curly bracket without a line break before
assertwould cause this issue:try { assert(0) } catch (err) {} function test() { assert(0) }
It looks like the expression parse is intentionally started at the line start. Modifying it from start to the actual offset seems to fix these cases, but not sure if it breaks others.
Lines 235 to 239 in 7629fb2
let start = 0; // Parse the read code until the correct expression is found. do { try { node = parseExpressionAt(code, start, { ecmaVersion: 11 }); // line 235 -let start = 0 +let start = offset
Reacted by Alex Yang@pd4d10 no
Lines 239 to 242 in 7629fb2
node = parseExpressionAt(code, start, { ecmaVersion: 11 }); start = node.end + 1 || start; // Find the CallExpression in the tree. node = findNodeAround(node, offset, 'CallExpression'); node = parseExpressionAt(code, start, { ecmaVersion: 11 });
this line will throw error with message
Unexpected token (1:2)and thecodearetry { assert(condition, message) } catch (e) { throw e } } // Now run tests console.log('Call assert proxy with slightly minified whitespace') try { assertProxySlightlyMinified(0) console.error(`assertProxySlightlyMinified(0); failed to cause an exception`) } catch (e) { console.log(`assertProxySlightlyMinified(0); generated exception: ${e}`) } console.log('Finished tests')and this
codewill not throw errorassert(condition, message) } catch (e) { throw e } } const assertProxySlightlyMinified = (condition, message) => { try { assert(condition, message) } catch (e) { throw e } } // Now run tests console.log('Call assert proxy with slightly minified whitespace') try { assertProxy(0) console.error(`assertProxySlightlyMinified(0); failed to cause an exception`) } catch (e) { console.log(`assertProxySlightlyMinified(0); generated exception: ${e}`) } console.log('Finished tests')@himself65 @pd4d10 is correct about that. The start is set to zero to include
assertor what ever name the user named it. It would otherwise only showok().I am currently looking into it (there is an easy solution but that would waste a lot of CPU time, so I am trying to find a proper fix).
Reacted by Alex Yang
Under Node 10 and Node 12, generating an exception from an assertion failure returns a different assertion failure message depending on differences in whitespace. It seems that with a certain whitespace configuration we see the Node 8 assertion failure message
0 == true, other configurations will generate the Node 10 messageThe expression evaluated to a falsy value. This issue only seems to affect the exception message, all other behaviour seems consistent.This will affect anything that runs minified source.
I have included a simple reproduction of the issue here