Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exception message for assert(0) on try block (#30872) #30897

Closed
wants to merge 1 commit into from

Conversation

himself65
Copy link
Member

@himself65 himself65 commented Dec 11, 2019

fix #30872

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the assert Issues and PRs related to the assert subsystem. label Dec 11, 2019
@@ -233,6 +233,9 @@ function parseCode(code, offset) {
}
let node;
let start = 0;
const regExp = code.match(/^.*try.*?{/);
if (regExp != null)
start = regExp.index + regExp[0].length;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are multiple cases that won't fit into this pattern. Think about e.g., the assertion being before the try / catch.

There are also probably more things that might cause failures, not just try / catch. I personally feel like this needs a deeper refactoring.

There is indeed one simple fix that will always work but that would cause CPU spikes in some cases, so I do not even propose it ;-).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there must be try keywords on the first line after reading the whole codes. Don't it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it could be behind the assertion. Think about e.g., minified code. I can not think of any regular expression that guarantees that things work as expected. We need an AST for it.

message: 'The expression evaluated to a falsy value:\n\n ' +
'assert.ok(0)\n'
}
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a test case like the second one.

@himself65 himself65 closed this Dec 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assert Issues and PRs related to the assert subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exception message for assert(0) depends on whitespace
3 participants