Skip to content

Commit

Permalink
Handle unexpected/missing keys on submission page.
Browse files Browse the repository at this point in the history
These can happen when we change the format of a config and go to
submissions in an old database.
  • Loading branch information
meisterT committed Oct 5, 2024
1 parent f1105ea commit a67ba2c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion webapp/src/Controller/Jury/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,9 @@ private function maybeGetErrors(string $type, string $expectedConfigString, stri
$observedConfig = $this->dj->jsonDecode($observedConfigString);
$errors = [];
foreach (array_keys($expectedConfig) as $k) {
if ($expectedConfig[$k] != $observedConfig[$k]) {
if (!array_key_exists($k, $observedConfig)) {
$errors[] = '- ' . preg_replace('/_/', ' ', $k) . ': missing';
} elseif ($expectedConfig[$k] != $observedConfig[$k]) {
if ($k === 'hash') {
$errors[] = '- script has changed';
} elseif ($k === 'entry_point') {
Expand All @@ -1265,6 +1267,11 @@ private function maybeGetErrors(string $type, string $expectedConfigString, stri
}
}
}
foreach (array_keys($observedConfig) as $k) {
if (!array_key_exists($k, $expectedConfig)) {
$errors[] = '- ' . preg_replace('/_/', ' ', $k) . ': unexpected';
}
}
if (!empty($errors)) {
$allErrors[] = $type . ' changes:';
array_push($allErrors, ...$errors);
Expand Down

0 comments on commit a67ba2c

Please sign in to comment.