-
Notifications
You must be signed in to change notification settings - Fork 113
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
Better error handling (HHVM compatibility) #33
Comments
I'm open to alternative suggestions, provided they don't involve writing an alternative DOM implementation. I think that in almost all cases, the parseErrors() function is used to report errors during parsing, so if there's a better place to put the errors, the patch should be trivial. |
it is not so easy. I'm attempting to remove I'm thinking to raise an exception when error occurs, but this will drastically change errors handling for this lib. |
@goetas I'm not sure an exception for each error is a good idea. So many documents have errors. You'd never be able to parse most things. It would really change error handling. Like @technosophos I'm open to suggestions. I'm just trying to think practically. |
Oh... sorry... missed this thread and commented straight on the commit. |
I'm also gonna ask @miso-belica for an opinion. More than anyone else, he's had to actually deal with parser errors. |
I think to raise an exception is very bad idea - malformed documents will not be possible to parse. I think the wrapper for Second solution is to return an array with |
Can be adopted something like this? $html5 = new HTML5($options = array());
$html5->setOptions($options);
$html5->getOptions(); // return: array
$html5->load($file); // return: DOMDocument|null
$html5->loadHTML($string); // return: DOMDocument|null
$html5->loadHTMLFragement($string); // return: DOMDocument|null
$html5->getErrors(); // return: array
$html5->hasErrors(); // return: boolean
$html5->parse($input); // return: DOMDocument|null
$html5->parseFragment($input); // return: ?|null
$html5->save($dom, $file, $options = array()); // return: boolean
$html5->saveHTML($dom, $options = array()); // return: string The proposed solution is a big change to the API... (can be created a new branch? |
I've been thinking a lot about @miso-belica 's proposal for returning two objects ($dom and $errors). I almost proposed something similar yesterday. I write a lot of Go, and this matches the Go error handling pattern... but deep down I feel like it is a little hacky in PHP. All things considered, I find myself leaning toward @goetas 's most recent solution: Get rid of the statics and have people use HTML5 instances. It feels like the most flexible, and gives us the ability to strategically grow the API later. According to our semantic versioning scheme, this would mean we'd have to release the change as a 2.0 release, but I'm okay with that. And if we really wanted to, we could easily adapt @miso-belica 's Go-like solution to provide an "easy" set of static methods that merely wrapped @goetas 's solution. @mattfarina -- what are your thoughts about committing to this level of API change? |
I agree with @technosophos |
I don't like the method @technosophos Yes returning a tuple from method is very uncommon in PHP (I'm Python guy the most). But I think of the methods |
@miso-belica your "options" argumentation is right. |
I think the idea of I like the idea of an object instead of a singleton. You can have to parsers side by side with different options this way. I'm torn on the use of This is one of those cases where we'd need to increment the major api version. But, I think that's ok. |
Moving discussion to #37 |
Hi!
I suggest to change error handling in
DOMTreeBuilder
. (https://github.com/Masterminds/html5-php/blob/master/src/HTML5/Parser/DOMTreeBuilder.php#L79)
Injecting a
errors
property toDOMDocument
is not so clean and won't always work, especially on HHVM.The text was updated successfully, but these errors were encountered: