all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager 1/2] vzdump: new: add add_error helper
Date: Tue, 19 Apr 2022 10:45:21 +0200	[thread overview]
Message-ID: <20220419084522.17916-1-f.ebner@proxmox.com> (raw)

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
 PVE/VZDump.pm | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index f34a5969..bdf270f7 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -505,19 +505,21 @@ sub new {
     PVE::Cluster::cfs_update(); # Pick up possible changes made by the hook script.
 
     my $errors = '';
+    my $add_error = sub {
+	my ($error) = @_;
+	$errors .= "\n" if $errors;
+	chomp($error);
+	$errors .= $error;
+    };
 
     if ($opts->{storage}) {
 	my $storage_cfg = PVE::Storage::config();
 	eval { PVE::Storage::activate_storage($storage_cfg, $opts->{storage}) };
-	if (my $err = $@) {
-	    chomp($err);
-	    $errors .= "could not activate storage '$opts->{storage}': $err";
-	}
+	$add_error->("could not activate storage '$opts->{storage}': $@") if $@;
 
 	my $info = eval { storage_info ($opts->{storage}) };
 	if (my $err = $@) {
-	    chomp($err);
-	    $errors .= "could not get storage information for '$opts->{storage}': $err";
+	    $add_error->("could not get storage information for '$opts->{storage}': $err");
 	} else {
 	    $opts->{dumpdir} = $info->{dumpdir};
 	    $opts->{scfg} = $info->{scfg};
@@ -525,7 +527,7 @@ sub new {
 	    $opts->{'prune-backups'} //= $info->{'prune-backups'};
 	}
     } elsif ($opts->{dumpdir}) {
-	$errors .= "dumpdir '$opts->{dumpdir}' does not exist"
+	$add_error->("dumpdir '$opts->{dumpdir}' does not exist")
 	    if ! -d $opts->{dumpdir};
     } else {
 	die "internal error";
@@ -537,8 +539,7 @@ sub new {
     $opts->{remove} = 0 if $opts->{'prune-backups'}->{'keep-all'};
 
     if ($opts->{tmpdir} && ! -d $opts->{tmpdir}) {
-	$errors .= "\n" if $errors;
-	$errors .= "tmpdir '$opts->{tmpdir}' does not exist";
+	$add_error->("tmpdir '$opts->{tmpdir}' does not exist");
     }
 
     if ($errors) {
-- 
2.30.2





             reply	other threads:[~2022-04-19  8:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-19  8:45 Fabian Ebner [this message]
2022-04-19  8:45 ` [pve-devel] [PATCH manager 2/2] fix #3955: vzdump: new: also send mail for error during job-init hook Fabian Ebner
2022-04-27  8:38 ` [pve-devel] applied-series: [PATCH manager 1/2] vzdump: new: add add_error helper Thomas Lamprecht

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=20220419084522.17916-1-f.ebner@proxmox.com \
    --to=f.ebner@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