mirror of
git://git.proxmox.com/git/pve-common.git
synced 2025-01-20 22:03:33 +03:00
SectionConfig: parse_config: add errors to result
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> Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
ad3ec2bb7c
commit
4b32ef6e2c
@ -311,6 +311,7 @@ sub parse_config {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
my $errors = [];
|
||||||
while (@lines) {
|
while (@lines) {
|
||||||
my $line = $nextline->();
|
my $line = $nextline->();
|
||||||
next if !$line;
|
next if !$line;
|
||||||
@ -349,7 +350,15 @@ sub parse_config {
|
|||||||
die "duplicate attribute\n" if defined($config->{$k});
|
die "duplicate attribute\n" if defined($config->{$k});
|
||||||
$config->{$k} = $plugin->check_value($type, $k, $v, $sectionId);
|
$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 {
|
} else {
|
||||||
warn "$errprefix (section '$sectionId') - ignore config line: $line\n";
|
warn "$errprefix (section '$sectionId') - ignore config line: $line\n";
|
||||||
@ -368,8 +377,12 @@ sub parse_config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $cfg = {
|
||||||
my $cfg = { ids => $ids, order => $order, digest => $digest};
|
ids => $ids,
|
||||||
|
order => $order,
|
||||||
|
digest => $digest
|
||||||
|
};
|
||||||
|
$cfg->{errors} = $errors if scalar(@$errors) > 0;
|
||||||
|
|
||||||
return $cfg;
|
return $cfg;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user