[MODULES-2462] Improve parseyaml function#511
Conversation
|
This is a continuation of #509. Please use "git push -f" to the PR's branch to keep the discussion in one place. We can continue here. Having a default value in case of parse errors is indeed something pick* cannot provide. to see this. |
f2249f2 to
eb948c4
Compare
* Add default value support Second argument will be returned if yaml cannot be parsed instead of false value * Update tests
|
Updated the function and spec. Also added same changes for parsejson function. |
|
+1 |
1 similar comment
|
+1 |
|
👍 Thanks for the contribution and updates @dmitryilyin ! |
[MODULES-2462] Improve parseyaml function
Maintain the old behavior in the case where the optional second parameter isn't passed. Also, adding arity is backwards incompatible since stdlib still supports 2.7, so remove that.
Fix backwards compatibility from #511
| YAML::load(arguments[0]) | ||
| begin | ||
| YAML::load(arguments[0]) || arguments[1] | ||
| rescue Exception |
There was a problem hiding this comment.
Hey, er, I realize this is merged by now. But this is a problem.
Don't ever rescue Exception.
Thoughts? This seems to be a recurring issue in stdlib, yes? Should I open a ticket for this?
There was a problem hiding this comment.
mumbles something about modulesync
|
In this case rescuing exception is appropriate because I really want to rescue every possible situation and return the default value. But I guess I can gather a list of exceptions the parser can raise and rescue only them. |
|
@dmitryilyin no you really cannot handle every possible exception. You wont handle NoMemoryError, SignalException, fatal, and probably shouldnt mask things like SyntaxError from the user |
|
Hmm, looks like there is quite a number of possible exceptions that can be raised by YAML module. There is a set of Psych exceptions, there can be Syck exceptions, there are C implementation of YAML loader and a number of Type errors and even Standard errors. So, because we are working with external module without a constant set of possible raised exceptions and we do want to rescue as much exceptions as possible, including Interrupt, Syntax error and even NoMemory error, it's appropriate to use anti-pattern of rescuing all exceptions here. |
|
FWIW I opened #586 to track this. The plethora of exceptions from (third party?) modules should inherit Also no, why would we want to rescue things like |
Second argument will be returned if yaml cannot be parsed
instead of false value