public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Thomas Lamprecht <t.lamprecht@proxmox.com>
Subject: [pve-devel] [PATCH/RFC common 4/5] SectionConfig: parse_config: add errors to result
Date: Mon, 21 Dec 2020 14:48:19 +0100	[thread overview]
Message-ID: <20201221134820.24038-5-f.ebner@proxmox.com> (raw)
In-Reply-To: <20201221134820.24038-1-f.ebner@proxmox.com>

so that callers can know about them. This is useful in places where we'd rather
abort then continue with a faulty configuration. For example, when reading the
storage configuration before executing a backup job.

Originally-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

I skimmed over the cascade of usages and could not find a problem with
introducing the new key. Potentially problematic code would be something
that's iterating over the keys for $cfg and do something bad with the
new 'errors', but AFAICS, there is no such code.

 src/PVE/SectionConfig.pm | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/PVE/SectionConfig.pm b/src/PVE/SectionConfig.pm
index b46b59e..af0af03 100644
--- a/src/PVE/SectionConfig.pm
+++ b/src/PVE/SectionConfig.pm
@@ -311,6 +311,7 @@ sub parse_config {
 	}
     };
 
+    my $errors = [];
     while (@lines) {
 	my $line = $nextline->();
 	next if !$line;
@@ -349,7 +350,15 @@ sub parse_config {
 			die "duplicate attribute\n" if defined($config->{$k});
 			$config->{$k} = $plugin->check_value($type, $k, $v, $sectionId);
 		    };
-		    warn "$errprefix (section '$sectionId') - unable to parse value of '$k': $@" if $@;
+		    if (my $err = $@) {
+			warn "$errprefix (section '$sectionId') - unable to parse value of '$k': $err";
+			push @$errors, {
+			    context => $errprefix,
+			    section => $sectionId,
+			    key => $k,
+			    err => $err,
+			};
+		    }
 
 		} else {
 		    warn "$errprefix (section '$sectionId') - ignore config line: $line\n";
@@ -368,8 +377,12 @@ sub parse_config {
 	}
     }
 
-
-    my $cfg = { ids => $ids, order => $order, digest => $digest};
+    my $cfg = {
+	ids => $ids,
+	order => $order,
+	digest => $digest
+    };
+    $cfg->{errors} = $errors if scalar(@$errors) > 0;
 
     return $cfg;
 }
-- 
2.20.1





  parent reply	other threads:[~2020-12-21 13:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-21 13:48 [pve-devel] [PATCH-SERIES] small vzdump improvements Fabian Ebner
2020-12-21 13:48 ` [pve-devel] [PATCH manager 1/5] vzdump: defaults: convert to prune-backups early enough Fabian Ebner
2020-12-21 14:33   ` [pve-devel] applied: " Thomas Lamprecht
2020-12-21 13:48 ` [pve-devel] [PATCH manager 2/5] vzdump: sendmail: fix html by closing the tags Fabian Ebner
2020-12-21 14:33   ` [pve-devel] applied: " Thomas Lamprecht
2020-12-21 13:48 ` [pve-devel] [PATCH manager 3/5] vzdump: fix error format for errors coming from storage_info Fabian Ebner
2020-12-21 14:33   ` [pve-devel] applied: " Thomas Lamprecht
2020-12-21 13:48 ` Fabian Ebner [this message]
2020-12-21 14:51   ` [pve-devel] applied: Re: [PATCH/RFC common 4/5] SectionConfig: parse_config: add errors to result Thomas Lamprecht
2020-12-21 13:48 ` [pve-devel] [PATCH/RFC manager 5/5] vzdump: make parse error for storage critical Fabian Ebner
2020-12-21 14:56   ` 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=20201221134820.24038-5-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    --cc=t.lamprecht@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal