Mailinglist Archive: yast-devel (127 mails)

< Previous Next >
[yast-devel] Ruby 'next' considered dangerous
  • From: Stefan Hundhammer <shundhammer@xxxxxxx>
  • Date: Tue, 17 Nov 2015 15:01:30 +0100
  • Message-id: <>
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:

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 <shundhammer@xxxxxxx>
YaST Developer

SUSE Linux GmbH
GF: Felix Imendörffer, Jane Smithard, Graham Norton; HRB 21284 (AG Nürnberg)
Maxfeldstr. 5, 90409 Nürnberg, Germany
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: yast-devel+owner@xxxxxxxxxxxx

< Previous Next >
Follow Ups