Page MenuHomePhabricator

Remove Exception typehint to fix T9637
ClosedPublic

Authored by Mnkras on Oct 26 2015, 6:11 PM.
Tags
None
Referenced Files
F13096497: D14342.diff
Thu, Apr 25, 4:52 PM
F13096439: D14342.diff
Thu, Apr 25, 4:36 PM
Unknown Object (File)
Sun, Apr 21, 7:26 AM
Unknown Object (File)
Fri, Apr 19, 3:49 PM
Unknown Object (File)
Mar 4 2024, 9:16 PM
Unknown Object (File)
Mar 4 2024, 6:08 PM
Unknown Object (File)
Mar 4 2024, 6:08 PM
Unknown Object (File)
Mar 4 2024, 6:08 PM
Subscribers

Details

Summary

Parse errors are caught by the error handler in PHP7, but they may not be of the type Exception
Remove type-hinting so that we can catch them and deal with them

Test Plan

arc unit --everything

Diff Detail

Repository
rPHU libphutil
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Mnkras retitled this revision from to Remove Exception typehint to fix T9637.
Mnkras updated this object.
Mnkras edited the test plan for this revision. (Show Details)
src/error/PhutilErrorHandler.php
88

This should be removed, right? Throwable doesn't exist until PHP7?

src/parser/xhpast/api/__tests__/XHPASTTreeTestCase.php
50–51

Unrelated?

Mnkras edited edge metadata.

Remove extra typehint

I think this is generally correct, but that handleException() should be pretty much unchanged. We should introduce a new handleThrowable() instead, probably, and set_exception_handler() to handleThrowable(), then have that pass the exception to handleException if it is really an Exception.

If it isn't, we should do "something else", but I don't know exactly what that something else is.

Mnkras added inline comments.
src/error/PhutilErrorHandler.php
88

Whoops. fixed

src/parser/xhpast/api/__tests__/XHPASTTreeTestCase.php
50–51

Forgot I had that commented out, that is supposed to fail (hence im assuming your //invalid comment,

in PHP7 that fails

Well, maybe this approach is fine, since Throwable seems to pretty much be exactly equivalent to Exception except that the equivalence is done in a PHP way so it's a huge mess.

But we should probably rename all of these from Exception -> Throwable to make it clear, I guess?

I think this is generally correct, but that handleException() should be pretty much unchanged. We should introduce a new handleThrowable() instead, probably, and set_exception_handler() to handleThrowable(), then have that pass the exception to handleException if it is really an Exception.

If it isn't, we should do "something else", but I don't know exactly what that something else is.

Would we handle anything differently? I don't think so, instead of fatals showing a white page with and some ascii art as we do now, it will show fatals like we show exceptions, unless we want to show the white page with the ascii art for fatals?

Well, maybe this approach is fine, since Throwable seems to pretty much be exactly equivalent to Exception except that the equivalence is done in a PHP way so it's a huge mess.

But we should probably rename all of these from Exception -> Throwable to make it clear, I guess?

Probably, I wasn't sure if these methods were used elsewhere and I would have to grep the codebases in everything

Yeah, my thinking was that we might end up calling some stuff that calls some other stuff that ends up breaking things, but that's dangerous to do on this pathway anyway.

Let's just do this change as-is, I guess, except put some sort of more meaningful TODO comment on the unit test thing? Like "this was valid as part of the syntax until PHP 7 even though it did not make sense, but is no longer parsed".

Add a TODO on a test that should have failed in <PHP7 but didn't

epriestley added a reviewer: epriestley.

Thanks! You should have commit access now.

src/parser/xhpast/api/__tests__/XHPASTTreeTestCase.php
50–51

Oh, we just pick up TODO: literally, not @todo.

This revision is now accepted and ready to land.Oct 26 2015, 6:24 PM
Mnkras edited edge metadata.

Reform my TODO: markup

This revision was automatically updated to reflect the committed changes.