Page MenuHomePhorge

RuntimeException: min(): Array must contain at least one element at DiffusionBlameController.php:201
Closed, ResolvedPublic

Description

Steps to reproduce:

Unclear.
Looking at downstream logs, running an old Phorge/Phabricator version but reading upstream code this can still happen:

[2023-08-21 04:15:00] EXCEPTION: (RuntimeException) min(): Array must contain at least one element at [<arcanist>/src/error/PhutilErrorHandler.php:261]
arcanist(), ava(), phabricator(), translations(), wmf-ext-misc()
  #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer, array) called at [<arcanist>/src/error/PhutilErrorHandler.php:261]
  #1 <#2> min(array) called at [<phabricator>/src/applications/diffusion/controller/DiffusionBlameController.php:201]
  #2 <#2> DiffusionBlameController::handleRequest(AphrontRequest) called at [<phabricator>/src/aphront/configuration/AphrontApplicationConfiguration.php:284]
  #3 phlog(RuntimeException) called at [<phabricator>/src/aphront/handler/PhabricatorAjaxRequestExceptionHandler.php:27]
  #4 PhabricatorAjaxRequestExceptionHandler::handleRequestThrowable(AphrontRequest, RuntimeException) called at [<phabricator>/src/aphront/configuration/AphrontApplicationConfiguration.php:751]
  #5 AphrontApplicationConfiguration::handleThrowable(RuntimeException) called at [<phabricator>/src/aphront/configuration/AphrontApplicationConfiguration.php:296]
  #6 AphrontApplicationConfiguration::processRequest(AphrontRequest, PhutilDeferredLog, AphrontPHPHTTPSink, MultimeterControl) called at [<phabricator>/src/aphront/configuration/AphrontApplicationConfiguration.php:204]
  #7 AphrontApplicationConfiguration::runHTTPRequest(AphrontPHPHTTPSink) called at [<phabricator>/webroot/index.php:35]'

Code in https://we.phorge.it/source/phorge/browse/master/src/applications/diffusion/controller/DiffusionBlameController.php basically does:

$identifiers = array_fuse($blame);
if ($identifiers) {
  ...
} else {
  $commits = array();
}
...
$epochs = array();
foreach ($identifiers as $identifier) {
  ...
  if ($commit) {
    $epoch = $commit->getEpoch();
  } else {
    $epoch = 0;
  }
  $epochs[] = $epoch;
}
...
$epoch_min = min($epochs);
$epoch_max = max($epochs);

$epochs can still be an empty array, as $epoch = 0 is only set when $identifiers is not null.