Revision b6865605
Von Sven Schöling vor mehr als 8 Jahren hinzugefügt
SL/Menu.pm | ||
---|---|---|
28 | 28 |
my $nodes_by_id = {}; |
29 | 29 |
for my $file (@files) { |
30 | 30 |
my $data; |
31 |
if ($yaml_xs) { |
|
32 |
$data = YAML::XS::LoadFile(File::Spec->catfile($path, $file)); |
|
33 |
} else { |
|
34 |
$data = YAML::LoadFile(File::Spec->catfile($path, $file)); |
|
35 |
} |
|
31 |
eval { |
|
32 |
if ($yaml_xs) { |
|
33 |
$data = YAML::XS::LoadFile(File::Spec->catfile($path, $file)); |
|
34 |
} else { |
|
35 |
$data = YAML::LoadFile(File::Spec->catfile($path, $file)); |
|
36 |
} |
|
37 |
1; |
|
38 |
} or do { |
|
39 |
die "Error while parsing $file: $@"; |
|
40 |
}; |
|
41 |
|
|
42 |
# check if this file is internally consistent. |
|
43 |
die 'not an array ref' unless $data && 'ARRAY' eq ref $data; # TODO get better diag to user |
|
44 |
|
|
45 |
# in particular duplicate ids tend to come up as a user error when editing the menu files |
|
46 |
my %uniq_ids; |
|
47 |
$uniq_ids{$_->{id}}++ && die "Error in $file: duplicate id $_->{id}" for @$data; |
|
48 |
|
|
36 | 49 |
_merge($nodes, $nodes_by_id, $data); |
37 | 50 |
} |
38 | 51 |
|
... | ... | |
57 | 70 |
sub _merge { |
58 | 71 |
my ($nodes, $by_id, $data) = @_; |
59 | 72 |
|
60 |
die 'not an array ref' unless $data && 'ARRAY' eq ref $data; # TODO check this sooner, to get better diag to user |
|
61 |
|
|
62 | 73 |
for my $node (@$data) { |
63 | 74 |
my $id = $node->{id}; |
64 | 75 |
|
Auch abrufbar als: Unified diff
Menu: Fehlerchecks beim yaml einlesen
2 häufige Fehler abfangen:
- wenn ids in einer datei doppelt vorkommen (passiert beim editieren)
- wenn YAML selber Fehler wirft gab es bisher ein HTTP 500