From 7e0558612b3335ce7e4bece6f4d50d04bbd2c93e Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 11 Jan 2016 14:15:09 -0800 Subject: [PATCH] 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 --- .../option/PhabricatorApplicationConfigOptions.php | 9 ++++++++- .../maniphest/constants/ManiphestTaskPriority.php | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/applications/config/option/PhabricatorApplicationConfigOptions.php b/src/applications/config/option/PhabricatorApplicationConfigOptions.php index d99cdf3101..491852eab6 100644 --- a/src/applications/config/option/PhabricatorApplicationConfigOptions.php +++ b/src/applications/config/option/PhabricatorApplicationConfigOptions.php @@ -21,7 +21,14 @@ abstract class PhabricatorApplicationConfigOptions extends Phobject { } if ($option->isCustomType()) { - return $option->getCustomObject()->validateOption($option, $value); + try { + 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()) { diff --git a/src/applications/maniphest/constants/ManiphestTaskPriority.php b/src/applications/maniphest/constants/ManiphestTaskPriority.php index 6bd1460628..16a35a9e83 100644 --- a/src/applications/maniphest/constants/ManiphestTaskPriority.php +++ b/src/applications/maniphest/constants/ManiphestTaskPriority.php @@ -116,7 +116,15 @@ final class ManiphestTaskPriority extends ManiphestConstants { 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) { if (!ctype_digit((string)$key)) { throw new Exception(