[yast-devel] Ruby 'next' considered dangerous
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
--
Stefan Hundhammer
participants (5)
-
Arvin Schnell
-
Josef Reidinger
-
Lukas Ocilka
-
Martin Vidner
-
Stefan Hundhammer