From bb7f2ea9055cec04a81d67f56f026e3f548e1273 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 16 Jun 2015 16:06:42 -0700 Subject: [PATCH] Fail gracefully on bad API call when building commit mail Summary: Ref T8574. This could fail because the target is disabled (as here), or doesn't have access to the API, or the API request needs to be satisfied by a different host which isn't available. In any of these cases, just show the failure and continue generating the mail. This field isn't important enough to block the mail, and many of these errors are permanent. (I'll follow up on T8574 with some more permanent ideas to address this class of issue.) Test Plan: Faked API call failure, generated mail, saw clean generation of mail with a failure message. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T8574 Differential Revision: https://secure.phabricator.com/D13319 --- .../PhabricatorCommitBranchesField.php | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/applications/repository/customfield/PhabricatorCommitBranchesField.php b/src/applications/repository/customfield/PhabricatorCommitBranchesField.php index 0d430f36a6..63a807ea55 100644 --- a/src/applications/repository/customfield/PhabricatorCommitBranchesField.php +++ b/src/applications/repository/customfield/PhabricatorCommitBranchesField.php @@ -29,18 +29,25 @@ final class PhabricatorCommitBranchesField 'callsign' => $this->getObject()->getRepository()->getCallsign(), ); - $branches_raw = id(new ConduitCall('diffusion.branchquery', $params)) - ->setUser($this->getViewer()) - ->execute(); + try { + $branches_raw = id(new ConduitCall('diffusion.branchquery', $params)) + ->setUser($this->getViewer()) + ->execute(); - $branches = DiffusionRepositoryRef::loadAllFromDictionaries($branches_raw); - if (!$branches) { - return; + $branches = DiffusionRepositoryRef::loadAllFromDictionaries( + $branches_raw); + if (!$branches) { + return; + } + + $branch_names = mpull($branches, 'getShortName'); + sort($branch_names); + $branch_text = implode(', ', $branch_names); + } catch (Exception $ex) { + $branch_text = pht('<%s: %s>', get_class($ex), $ex->getMessage()); } - $branch_names = mpull($branches, 'getShortName'); - sort($branch_names); - $body->addTextSection(pht('BRANCHES'), implode(', ', $branch_names)); + $body->addTextSection(pht('BRANCHES'), $branch_text); } }