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

parser: fix exceptions being ignored #143

Closed
wants to merge 1 commit into from
Closed

Conversation

belochub
Copy link
Member

@belochub belochub commented May 7, 2017

  • Avoid continuing execution after exception is thrown
    inside a parsing method call.
  • Return undefined when possible in cases of exceptions
    raising in all of the methods (to reduce memory usage).

Fixes: #142

* Avoid continuing execution after exception is thrown
  inside a parsing method call.
* Return undefined when possible in cases of exceptions
  raising in all of the methods (to reduce memory usage).

Fixes: #142
Copy link
Member

@lundibundi lundibundi left a comment

Choose a reason for hiding this comment

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

LGTM, but I'd like if function calls in 'try/catch' used same style - all args in one line with or without newline after equals or each arg on separate line, to make code more consistent and easy to read.

TryCatch trycatch(isolate);
result =
(kParseFunctions[type])(isolate, str + start_pos, end, &parsed_size);

Copy link
Member

Choose a reason for hiding this comment

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

Just curious, is this space necessary, as you don't have it in the other places?

@aqrln
Copy link
Member

aqrln commented May 8, 2017

The thing I don't like in this approach is that we basically use JavaScript exceptions instead of C++ ones to handle errors inside the C++ code. How much is the performance overhead, btw? I'd prefer to handle errors in C++ code properly using any pattern you will find appropriate and only throwing JavaScript exceptions from the highest level functions.

@belochub
Copy link
Member Author

belochub commented May 8, 2017

@aqrln, well, I haven't checked the performance overhead, but maybe you can do it if you want.
There aren't that many possible solutions to handle this differently, one of which is to just add one or two more arguments to each of the parser functions: the first one indicating whether error has occurred and possibly the second one, used to return the error message if any, but that looks like strangely replicating exceptions functionality without actually using them.
Do you maybe have any other ideas on how to solve this problem in a more elegant way?

@aqrln
Copy link
Member

aqrln commented May 8, 2017

@belochub

but that looks like strangely replicating exceptions functionality without actually using them

Well, that's what Google C++ Style Guide suggests to do, isn't that?

@belochub
Copy link
Member Author

belochub commented May 8, 2017

@aqrln, I, probably, should have clarified that I was talking about JS exceptions in the part you quoted, and Google C++ Style Guide gives no opinion on them, because it is out of its scope, obviously.

@aqrln
Copy link
Member

aqrln commented May 8, 2017

@belochub yeah, and my point is that using JavaScript exceptions instead of C++ ones isn't the best way to work around the limitations induced by the styleguide ;)

That said, I do have to admit that we currently have a bug in the parser and this PR resolves the issue in an acceptable (though not very perfect to me) way, so I'm not gonna stand against it. Let's just fix it. I'm okay with discussing the preferred way of handling errors inside the parser internals and refactoring the code later, if there'll be a need to do so.

@belochub
Copy link
Member Author

belochub commented May 8, 2017

@aqrln, right, you are saying that it is not a perfect way of fixing it, but do you have a better solution in mind right now?
The way I proposed in previous comments is worse in my opinion, but I also had an idea of somewhat mixed usage of exceptions and returning boolean value indicating that exception has been raised. But it is just another way of avoiding v8::TryCatch and it still uses JavaScript exceptions, thus I don't see much difference with the implementation in this PR.

@aqrln
Copy link
Member

aqrln commented May 8, 2017

@belochub

do you have a better solution in mind right now?

I don't. I would propose it immediately if I did. The point that I'm trying to communicate is just this doesn't feel like quite the best approach to me, but I'm fine with it as long as there are no better alternatives.

@belochub
Copy link
Member Author

belochub commented May 8, 2017

Okay then, let's lend this as it is and whenever we get a better solution we will discuss it and refactor this part.

aqrln pushed a commit that referenced this pull request May 8, 2017
* Avoid continuing execution after exception is thrown
  inside a parsing method call.
* Return undefined when possible in cases of exceptions
  raising in all of the methods (to reduce memory usage).

PR-URL: #143
Fixes: #142
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
@aqrln
Copy link
Member

aqrln commented May 8, 2017

Landed in 29b3e19. Thanks!

@aqrln aqrln closed this May 8, 2017
@aqrln aqrln deleted the parser-fix-exceptions branch May 8, 2017 15:11
belochub added a commit that referenced this pull request May 24, 2017
Avoid using TryCatch introduced in
29b3e19 by using
MaybeLocal instead.

Refs: #143
belochub added a commit that referenced this pull request May 24, 2017
Avoid using TryCatch introduced in
29b3e19 by using
MaybeLocal instead.

Refs: #143
aqrln pushed a commit that referenced this pull request May 26, 2017
Avoid using TryCatch introduced in
29b3e19 by using
MaybeLocal instead.

PR-URL: #178
Refs: #143
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
belochub added a commit that referenced this pull request Jan 22, 2018
* Avoid continuing execution after exception is thrown
  inside a parsing method call.
* Return undefined when possible in cases of exceptions
  raising in all of the methods (to reduce memory usage).

PR-URL: #143
Fixes: #142
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
belochub added a commit that referenced this pull request Jan 22, 2018
Avoid using TryCatch introduced in
29b3e19 by using
MaybeLocal instead.

PR-URL: #178
Refs: #143
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
belochub added a commit that referenced this pull request Jan 22, 2018
* Avoid continuing execution after exception is thrown
  inside a parsing method call.
* Return undefined when possible in cases of exceptions
  raising in all of the methods (to reduce memory usage).

PR-URL: #143
Fixes: #142
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
belochub added a commit that referenced this pull request Jan 22, 2018
Avoid using TryCatch introduced in
29b3e19 by using
MaybeLocal instead.

PR-URL: #178
Refs: #143
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
@belochub belochub mentioned this pull request Jan 22, 2018
belochub added a commit to metarhia/mdsf that referenced this pull request Jul 19, 2018
* Avoid continuing execution after exception is thrown
  inside a parsing method call.
* Return undefined when possible in cases of exceptions
  raising in all of the methods (to reduce memory usage).

PR-URL: metarhia/jstp#143
Fixes: metarhia/jstp#142
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
belochub added a commit to metarhia/mdsf that referenced this pull request Jul 19, 2018
Avoid using TryCatch introduced in
29b3e197ae4c33d1b9057b57731b4c422de764f3 by using
MaybeLocal instead.

PR-URL: metarhia/jstp#178
Refs: metarhia/jstp#143
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
belochub added a commit to metarhia/mdsf that referenced this pull request Jul 19, 2018
* Avoid continuing execution after exception is thrown
  inside a parsing method call.
* Return undefined when possible in cases of exceptions
  raising in all of the methods (to reduce memory usage).

PR-URL: metarhia/jstp#143
Fixes: metarhia/jstp#142
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
belochub added a commit to metarhia/mdsf that referenced this pull request Jul 19, 2018
Avoid using TryCatch introduced in
29b3e197ae4c33d1b9057b57731b4c422de764f3 by using
MaybeLocal instead.

PR-URL: metarhia/jstp#178
Refs: metarhia/jstp#143
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
belochub added a commit to metarhia/mdsf that referenced this pull request Jul 21, 2018
* Avoid continuing execution after exception is thrown
  inside a parsing method call.
* Return undefined when possible in cases of exceptions
  raising in all of the methods (to reduce memory usage).

PR-URL: metarhia/jstp#143
Fixes: metarhia/jstp#142
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
belochub added a commit to metarhia/mdsf that referenced this pull request Jul 21, 2018
Avoid using TryCatch introduced in
29b3e197ae4c33d1b9057b57731b4c422de764f3 by using
MaybeLocal instead.

PR-URL: metarhia/jstp#178
Refs: metarhia/jstp#143
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants