Unhandled Composer Stager exceptions leave the update process in an indeterminate state

Created on 25 April 2022, over 2 years ago
Updated 17 March 2023, over 1 year ago

Problem/Motivation

Right now, we carefully handle the cases where a subscriber to one of our events throws an exception or flags a validation error -- we destroy the stage. Boom.

However, we do not handle exceptions thrown by Composer Stager, which is a problem, because if one of those operations fails, the stage, at minimum, is in an indeterminate state and should probably be destroyed.

📌 Inform the site admin if Composer Stager's committer failed, possibly leaving the site in a half-updated state Fixed we handle the case where there this is exception in commit. But we don't handle exceptions in Begin or Require

Steps to reproduce

Proposed resolution

The following lines in Stage should be wrapped in try-catch structures which can handle Composer Stager exceptions, destroy the stage, and re-throw a StageException that wraps the original exception.

$this->beginner->begin($active_dir, $stage_dir, new PathList($event->getExcludedPaths()), NULL, $timeout);
$this->stager->stage($command, $active_dir, $stage_dir, NULL, $timeout);

It `begin()` we should definitely just destroy the stage because nothing has been done yet and we won't know what files have been copied over.
in stage() we may not want to destroy the stage if the exception is a `\PhpTuf\ComposerStager\Domain\Exception\InvalidArgumentException` or a `\PhpTuf\ComposerStager\Domain\Exception\PreconditionException` because in that case the composer would not have actually been attempted. Some users of the stage might still want to work in the stage. In Automatic Updates and I think in Project browser the stage should be destroyed.

Remaining tasks

Make the aforementioned change and add test coverage.

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇺🇸United States phenaproxima Massachusetts

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024