1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Fix excessively harsh validation of certain complex configuration

Summary:
See IRC. We're supposed to repair configuration, but if custom validators throw a generic `Exception` or use `PhutilTypeSpec` to do a check, we may explode way harder than we intend to.

Instead, soften these exceptions into validation exceptions so we repair configuration, raise a setup issue, and continue.

Test Plan: {F1059609}

Reviewers: chad

Reviewed By: chad

Differential Revision: https://secure.phabricator.com/D14998
This commit is contained in:
epriestley 2016-01-11 14:15:09 -08:00
parent 8e1b2f9861
commit 7e0558612b
2 changed files with 17 additions and 2 deletions

View file

@ -21,7 +21,14 @@ abstract class PhabricatorApplicationConfigOptions extends Phobject {
} }
if ($option->isCustomType()) { if ($option->isCustomType()) {
try {
return $option->getCustomObject()->validateOption($option, $value); return $option->getCustomObject()->validateOption($option, $value);
} catch (Exception $ex) {
// If custom validators threw exceptions, convert them to configuation
// validation exceptions so we repair the configuration and raise
// an error.
throw new PhabricatorConfigValidationException($ex->getMessage());
}
} }
switch ($option->getType()) { switch ($option->getType()) {

View file

@ -116,7 +116,15 @@ final class ManiphestTaskPriority extends ManiphestConstants {
return $config; return $config;
} }
public static function validateConfiguration(array $config) { public static function validateConfiguration($config) {
if (!is_array($config)) {
throw new Exception(
pht(
'Configuration is not valid. Maniphest priority configurations '.
'must be dictionaries.',
$config));
}
foreach ($config as $key => $value) { foreach ($config as $key => $value) {
if (!ctype_digit((string)$key)) { if (!ctype_digit((string)$key)) {
throw new Exception( throw new Exception(