On Tue, 17 Nov 2015 15:01:30 +0100
Stefan Hundhammer
We just had to deal with a P1 bug caused by a stray 'next' statement in the Ruby code that did not return a value:
https://bugzilla.suse.com/show_bug.cgi?id=955216#c11
We seem to have a large number of such 'next' statements in our code. Everybody please be aware that this can cause great trouble in certain iterator methods that expect a return value from their code block!
In this case, it was Hash::reduce(). If you simply call 'next' in its loop, it will merrily clobber its accumulator with 'nil', very likely causing a crash in the next loop iteration.
IMHO it's sad that we do have tools that enforce stuff like one newline too many between function definitions, but critical things like not returning a value from a block that is required to return one goes completely unnoticed. And we were even lucky that our QA caught this problem, not some unsuspecting customer in the field.
What can we do to improve this?
I suggest some Ruby experts to collect all such functions that are potentially in danger of this problem and then grep through the code where they are used, and if any similar 'next' without a required return value is used. But that's just a one-time effort. Maybe there is some tool out there that can automate that for us.
Kind regard
Hi, well, there is already quite powerful parsers and I believe it won't be so hard to improve rubocop to check it. On other hand it is exactly same problem as using return without value. So for me it is same as ``` def recursive return unless funny_condition if a == 1 return obj else return obj.recursive end end ``` And to be honest it can happen in any code in any language ( just depending how often it can happen ). E.g. in ycp one nil can result in cascade of nils. What is ruby philosophy how to solve it? Tests. Do not trust code that is not tested. Of course some tools can detect some misusage, but only good tests can prove that code really works. Josef -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org