Skip to content
Snippets Groups Projects
Commit 910a5ee1 authored by omkar podey's avatar omkar podey Committed by Adam G-H
Browse files

Issue #3308828 by omkar.podey, phenaproxima: Handle the case where the marker...

Issue #3308828 by omkar.podey, phenaproxima: Handle the case where the marker file has been detected but can't be decoded
parent 7d40ee30
No related branches found
No related tags found
No related merge requests found
......@@ -78,7 +78,12 @@ final class FailureMarker {
if (file_exists($path)) {
$data = file_get_contents($path);
$data = Json::decode($data);
try {
$data = json_decode($data, TRUE, 512, JSON_THROW_ON_ERROR);
}
catch (\JsonException $exception) {
throw new ApplyFailedException('Failure marker file exists but cannot be decoded.', $exception->getCode(), $exception);
}
throw new ApplyFailedException($data['message']);
}
......
<?php
namespace Drupal\Tests\package_manager\Kernel;
use Drupal\package_manager\Exception\ApplyFailedException;
/**
* @coversDefaultClass \Drupal\package_manager\FailureMarker
*
* @group package_manager
*/
class FailureMarkerTest extends PackageManagerKernelTestBase {
/**
* @covers ::assertNotExists
*/
public function testExceptionIfExists(): void {
$failure_marker = $this->container->get('package_manager.failure_marker');
$failure_marker->write($this->createStage(), 'Disastrous catastrophe!');
$this->expectException(ApplyFailedException::class);
$this->expectExceptionMessage('Disastrous catastrophe!');
$failure_marker->assertNotExists();
}
/**
* Tests that an exception is thrown if the marker file contains invalid JSON.
*
* @covers ::assertNotExists
*/
public function testExceptionForInvalidJson(): void {
$failure_marker = $this->container->get('package_manager.failure_marker');
// Write the failure marker with invalid JSON.
file_put_contents($failure_marker->getPath(), '{}}');
$this->expectException(ApplyFailedException::class);
$this->expectExceptionMessage('Failure marker file exists but cannot be decoded.');
$failure_marker->assertNotExists();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment