all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Nicolas Frey <n.frey@proxmox.com>
Subject: Re: [pve-devel] [PATCH pve-common] cli: fix #6762: only copy properties if defined
Date: Tue, 7 Oct 2025 16:47:10 +0200	[thread overview]
Message-ID: <920a868c-06ba-4192-9b8b-eb0b55cacac5@proxmox.com> (raw)
In-Reply-To: <20251007135638.136536-1-n.frey@proxmox.com>

Am 07.10.25 um 15:56 schrieb Nicolas Frey:
> Adds a defined check to the copy, as to not result in the bugfixes
> reported error when double tabbing on `pveceph status`.
Feel encouraged to include errors in verbatim in commit message,
while we own bugzilla.proxmox.com and thus it's unlikely that it
will be gone without notice or migration it's still always nice to
keep git commits self-sufficient w.r.t core information. Makes it
also easier to find a commit if one just searches for the error
message.

> 
> Fixes: https://bugzilla.proxmox.com/show_bug.cgi?id=6762
> Signed-off-by: Nicolas Frey <n.frey@proxmox.com>
> ---
>  src/PVE/CLIHandler.pm | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/PVE/CLIHandler.pm b/src/PVE/CLIHandler.pm
> index 89cb7b7..cdd71c7 100644
> --- a/src/PVE/CLIHandler.pm
> +++ b/src/PVE/CLIHandler.pm
> @@ -455,7 +455,8 @@ my $print_bash_completion = sub {
>  
>      my $info = $class->map_method_by_name($name);
>  
> -    my $prop = { %{ $info->{parameters}->{properties} } }; # copy
> +    my $prop = { %{ $info->{parameters}->{properties} } }
> +        if defined $info->{parameters}->{properties}; # copy

You cannot know without having lots of perl experience, or having had
the bad luck of debugging this yourself early on, but a conditional
declaration of a variable is Real Bad™ perl, as it will retain the
value of the last time the condition held true for the case it's false
now.

See the NOTE at the end of the "Statement Modifiers" [0] section for
details.

[0]: https://perldoc.perl.org/perlsyn#Statement-Modifiers

Safe alternatives are:

my $prop;
$prop = { $info->{parameters}->{properties}->%* } if defined($info->{parameters}->{properties});

Similar, but with normal if block, which can be combined with adding a
intermediate variable.

my $prop;
if (defined(my $properties = $info->{parameters}->{properties})) {
    $prop = { $properties->%* }; # clone
}

Alternatively, one can use a intermediate variable + a fallback value

my $parameter_properties = $info->{parameters}->{properties} // {};
my $prop = { $parameter_properties->%* }; # copy

Alternatively, one can use a ternary statement:

$prop = defined($info->{parameters}->{properties})
 ? { $info->{parameters}->{properties}->%* }
 : {};

The last one is IMO a bit long here.


>      $prop = { %$prop, %$formatter_properties } if $formatter_properties;
>  
>      my $print_parameter_completion = sub {



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

  reply	other threads:[~2025-10-07 14:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-07 13:56 Nicolas Frey
2025-10-07 14:47 ` Thomas Lamprecht [this message]
2025-10-07 15:13   ` Nicolas Frey
2025-10-07 15:18 ` Nicolas Frey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=920a868c-06ba-4192-9b8b-eb0b55cacac5@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=n.frey@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal