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 6, 2024
1 parent 652bb06 commit 6c79e0d
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 @@ -1258,7 +1258,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 @@ -1270,6 +1272,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 6c79e0d

Please sign in to comment.