[pve-devel] [PATCH installer] run env: use default error message if country detection failed with empty string

Christoph Heiss c.heiss at proxmox.com
Tue Mar 26 14:29:19 CET 2024


Bit of perl fun again.
$err from detect_country_tracing_to() can be empty string under certain
circumstances (according to a forum post [0]). The // operator
evaluates an empty as true, thus `warn` receives an empty string to and
just prints

  Warning: something wrong at /usr/share/perl5/proxmox/Install/RunEnv.pm line 305

Which isn't particular helpful. Use the || operator instead, that
evaluates an empty string as false and thus would fall back to the
generic error message.

A minimal reproducer/example for completeness sake:

  #!/usr/bin/env perl
  use strict;
  use warnings;

  warn ('' // "unable to detect country\n");
  warn ('' || "unable to detect country\n");

gives

  Warning: something's wrong at ./test.pl line 5.
  unable to detect country

[0] https://forum.proxmox.com/threads/blank-screen-while-installing.143928/

Signed-off-by: Christoph Heiss <c.heiss at proxmox.com>
---
 Proxmox/Install/RunEnv.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Proxmox/Install/RunEnv.pm b/Proxmox/Install/RunEnv.pm
index 25b6bb3..39505d0 100644
--- a/Proxmox/Install/RunEnv.pm
+++ b/Proxmox/Install/RunEnv.pm
@@ -302,7 +302,7 @@ sub query_installation_environment : prototype() {
     if (defined($country)) {
 	$output->{country} = $country;
     } else {
-	warn ($err // "unable to detect country\n");
+	warn ($err || "unable to detect country\n");
     }

     return $output;
--
2.43.1





More information about the pve-devel mailing list