[pve-devel] [PATCH/RFC common 4/5] SectionConfig: parse_config: add errors to result
Fabian Ebner
f.ebner at proxmox.com
Mon Dec 21 14:48:19 CET 2020
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 at proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner at 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
More information about the pve-devel
mailing list