Mailinglist Archive: yast-devel (87 mails)

< Previous Next >
Re: [yast-devel] Feedback needed! Hack Week project to re-define storage-ng API
  • From: Josef Reidinger <jreidinger@xxxxxxx>
  • Date: Fri, 24 Feb 2017 13:51:42 +0100
  • Message-id: <20170224135142.216a35da@linux-vvcf.privatesite>
On Fri, 24 Feb 2017 10:55:25 +0100
Arvin Schnell <aschnell@xxxxxxxx> wrote:

On Fri, Feb 24, 2017 at 09:28:24AM +0100, Josef Reidinger wrote:

What is difference between specified exception and nil class
exception? in both case it is programmer error and need to be
fixed. If we do not want exception, it can be possible to Null
object pattern and define behavior for non-existing filesystem,

We also had that discussion already. Even in Wikipedia the Null
Object pattern gets strong criticism.

Link provided -

I agree with criticism there that it should not replace check for nil
just for better readability. But in this case it is valid storage setup
and I think it is possible to find reasonable behavior in such case
( like user friendly to_s method or raise exception if needed ). Second
half of criticism I think not affect ruby and storage-ng.

Let see how it will work in reality in bootloader code with storage-ng.


def with_btrfs?(partition)
partition.filesystem.type == ::Storage::FsType_BTRFS
rescue Storage::WrongNumberOfChildren, Storage::DeviceHasWrongType
# No filesystem in the partition

can be:

def with_btrfs?(partition)

when there is not filesystem in partition, we have NoneFilesystem with
NoneType that obviously return false for btrfs?

another example from current yast-storage-ng


partition_table = @disk.partition_table
partition_table.partitions.each do |partition|
ret << partition.table_row(FIELDS)
rescue Storage::WrongNumberOfChildren, Storage::DeviceHasWrongType

Can be without this begin and rescue as for not existing partition
table there is no partitions.

I was curious how often this pattern can be seen in yast-storage-ng so
I try

grep -R "rescue.*Storage::DeviceHasWrongType" * | wc -l

and result is 33

So it is repeated 33 times. That code really "smells" for me.

To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: yast-devel+owner@xxxxxxxxxxxx

< Previous Next >
Follow Ups