Page MenuHomePhabricator

It's currently not possible to set a Harbormaster target to failed without throwing exception
Closed, ResolvedPublic

Description

The harbormaster target logic is this:

try {
  $status_pending = HarbormasterBuildTarget::STATUS_PENDING;
  if ($target->getTargetStatus() == $status_pending) {
    $target->setTargetStatus(HarbormasterBuildTarget::STATUS_BUILDING);
    $target->save();
  }

  $implementation = $target->getImplementation();
  $implementation->execute($build, $target);

  $next_status = HarbormasterBuildTarget::STATUS_PASSED;
  if ($implementation->shouldWaitForMessage($target)) {
    $next_status = HarbormasterBuildTarget::STATUS_WAITING;
  }

  $target->setTargetStatus($next_status);
  $target->save();
} catch (PhabricatorWorkerYieldException $ex) {
  // If the target wants to yield, let that escape without further
  // processing. We'll resume after the task retries.
  throw $ex;
} catch (Exception $ex) {
  phlog($ex);

  try {
    $log = $build->createLog($target, 'core', 'exception');
    $start = $log->start();
    $log->append((string)$ex);
    $log->finalize($start);
  } catch (Exception $log_ex) {
    phlog($log_ex);
  }

  $target->setTargetStatus(HarbormasterBuildTarget::STATUS_FAILED);
  $target->save();
}

Thus the only way to mark a target as failed is to throw an exception.

Marking the build as failed like this:

$build->setBuildStatus(HarbormasterBuild::STATUS_FAILED);

doesn't work either, because the Harbormaster build engine updates the build status based on the targets.

Event Timeline

hach-que assigned this task to epriestley.
hach-que raised the priority of this task from to Needs Triage.
hach-que updated the task description. (Show Details)
hach-que added a project: Harbormaster.
hach-que added a subscriber: hach-que.

This is by design. Why do you want to fail builds without failing any targets?

It's not that I don't want to fail build targets, it's that the only way to fail a build target is by throwing an exception. Setting the build target status to STATUS_FAILED doesn't result get used because of this line:

$next_status = HarbormasterBuildTarget::STATUS_PASSED;

It should probably be:

$next_status = $target->getBuildTargetStatus();

or something.

Why do you want to change the status explicitly?

In my scenario I'm performing a build on Bamboo and pulling the logs and build status across. If I throw an exception just to fail the target, then I get an additional exception log appearing, even though there's no useful information to gain from having it there (it failed because Bamboo indicates it failed, and the actual reason can be found in the logs that are automatically pulled from Bamboo).

Would having a JustFailThisTargetAndDontWorryAboutTheLogsException you could throw (or some convenience method to throw it on your behalf) resolve that?

(Particularly, the current "FAILED" branch is probably really "UNEXPECTED_SURPRISE_ERROR" once we distinguish between the two.)

Yeah that'd solve the issue as well (I was just of the perception that exceptions were going to be used for STATUS_ERROR and setting the status would be for STATUS_FAILED).