Skip to content

Commit 422eb72

Browse files
MCLOUD-5442: Error is not displayed for extended scenario on deploy phase (magento#712)
1 parent a66ffdb commit 422eb72

File tree

9 files changed

+96
-22
lines changed

9 files changed

+96
-22
lines changed

config/services.xml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
<services>
77
<defaults autowire="true" autoconfigure="true" public="true" />
8-
<!-- ... -->
98

109
<prototype namespace="Magento\MagentoCloud\" resource="../src/*" exclude="../src/{Test}"/>
1110

@@ -30,13 +29,6 @@
3029
<service id="Magento\MagentoCloud\Filesystem\FileSystemException" autowire="false" />
3130
<service id="Magento\MagentoCloud\Filesystem\Flag\ConfigurationMismatchException" autowire="false" />
3231
<service id="Magento\MagentoCloud\Shell\UtilityException" autowire="false" />
33-
<service id="Magento\MagentoCloud\Filesystem\Flag\Pool">
34-
<argument type="collection">
35-
<argument key="regenerate">var/.regenerate</argument>
36-
<argument key="scd_in_build">.static_content_deploy</argument>
37-
<argument key="deploy_is_failed">var/.deploy_is_failed</argument>
38-
</argument>
39-
</service>
4032
<service id="Magento\MagentoCloud\Filesystem\SystemList" autowire="false" />
4133
<service id="Magento\MagentoCloud\Package\UndefinedPackageException" autowire="false" />
4234
<service id="Magento\MagentoCloud\Scenario\Exception\ProcessorException" autowire="false" />
@@ -61,6 +53,7 @@
6153
<service id="Magento\MagentoCloud\Shell\ProcessException" autowire="false" />
6254
<service id="Symfony\Component\Yaml\Parser" autowire="false" />
6355
<service id="Symfony\Component\Yaml\Dumper" autowire="false" />
56+
<!-- Service argument configuration -->
6457
<service id="Magento\MagentoCloud\Filesystem\Flag\Pool">
6558
<argument type="collection">
6659
<argument key="regenerate">var/.regenerate</argument>

src/App/Container.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,19 @@ private function createComposerInstance(SystemList $systemList): Composer
8989
}
9090

9191
/**
92-
* {@inheritdoc}
93-
*
94-
* @see create() For factory-like usage
92+
* @inheritDoc
9593
*/
9694
public function get($id)
9795
{
98-
return $this->container->get($id);
96+
try {
97+
return $this->container->get($id);
98+
} catch (Exception $exception) {
99+
throw new ContainerException(
100+
$exception->getMessage(),
101+
$exception->getCode(),
102+
$exception
103+
);
104+
}
99105
}
100106

101107
/**

src/App/ContainerInterface.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ interface ContainerInterface extends \Psr\Container\ContainerInterface
1818
* @param string $abstract
1919
* @param array $params
2020
* @return mixed
21+
*
22+
* @throws ContainerException
2123
*/
2224
public function create(string $abstract, array $params = []);
2325

@@ -29,4 +31,13 @@ public function create(string $abstract, array $params = []);
2931
* @return void
3032
*/
3133
public function set(string $id, $service): void;
34+
35+
/**
36+
* {@inheritDoc}
37+
*
38+
* @throws ContainerException
39+
*
40+
* @see create() For factory-like usage
41+
*/
42+
public function get($id);
3243
}

src/App/ErrorHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\MagentoCloud\App;
99

10+
use RuntimeException;
11+
1012
/**
1113
* An error handler that converts runtime errors into exceptions.
1214
*/
@@ -43,7 +45,7 @@ class ErrorHandler
4345
* @param string $errorFile
4446
* @param int $errorLine
4547
* @return bool
46-
* @throws \RuntimeException
48+
* @throws RuntimeException
4749
*/
4850
public function handle(int $errorNo, string $errorStr, string $errorFile, int $errorLine): bool
4951
{

src/App/GenericException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\MagentoCloud\App;
99

10+
use Throwable;
11+
1012
/**
1113
* Base exception for general purposes.
1214
*/
@@ -15,7 +17,7 @@ class GenericException extends \Exception
1517
/**
1618
* @inheritDoc
1719
*/
18-
public function __construct(string $message, int $code = 0, \Throwable $previous = null)
20+
public function __construct(string $message, int $code = 0, Throwable $previous = null)
1921
{
2022
parent::__construct($message, $code, $previous);
2123
}

src/Scenario/Processor.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
namespace Magento\MagentoCloud\Scenario;
99

10-
use Magento\MagentoCloud\App\GenericException;
1110
use Magento\MagentoCloud\Package\Manager;
11+
use Magento\MagentoCloud\Step\StepException;
1212
use Magento\MagentoCloud\Step\StepInterface;
1313
use Magento\MagentoCloud\Scenario\Exception\ProcessorException;
1414
use Psr\Log\LoggerInterface;
15+
use Throwable;
1516

1617
/**
1718
* Process given scenarios.
@@ -67,14 +68,24 @@ public function execute(array $scenarios): void
6768

6869
$this->logger->debug(sprintf('Step "%s" finished', $name));
6970
});
70-
} catch (GenericException $exception) {
71+
} catch (StepException $exception) {
7172
$this->logger->error($exception->getMessage());
7273

7374
throw new ProcessorException(
7475
$exception->getMessage(),
7576
$exception->getCode(),
7677
$exception
7778
);
79+
} catch (Throwable $exception) {
80+
$message = 'Unhandled error: ' . $exception->getMessage();
81+
82+
$this->logger->error($message);
83+
84+
throw new ProcessorException(
85+
$message,
86+
$exception->getCode(),
87+
$exception
88+
);
7889
}
7990

8091
$this->logger->info('Scenario(s) finished');

src/Shell/Process.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
/**
1313
* Runs console commands.
14+
*
1415
* @codeCoverageIgnore
1516
*/
1617
class Process extends \Symfony\Component\Process\Process implements ProcessInterface
@@ -20,18 +21,18 @@ class Process extends \Symfony\Component\Process\Process implements ProcessInter
2021
*
2122
* {@inheritdoc}
2223
*/
23-
public function getOutput()
24+
public function getOutput(): string
2425
{
2526
return trim(parent::getOutput(), PHP_EOL);
2627
}
2728

2829
/**
2930
* @inheritdoc
3031
*/
31-
public function execute()
32+
public function execute(): void
3233
{
3334
try {
34-
parent::mustRun();
35+
$this->mustRun();
3536
} catch (ProcessFailedException $e) {
3637
$process = $e->getProcess();
3738

src/Shell/ProcessFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class ProcessFactory
1717
*
1818
* @param array $params
1919
* @return Process|ProcessInterface
20-
* @throws \RuntimeException if Process can't be created
2120
*/
2221
public function create(array $params): ProcessInterface
2322
{

src/Test/Unit/Scenario/ProcessorTest.php

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\MagentoCloud\Test\Unit\Scenario;
99

1010
use Magento\MagentoCloud\Package\Manager;
11+
use Magento\MagentoCloud\Step\StepException;
1112
use Magento\MagentoCloud\Step\StepInterface;
1213
use Magento\MagentoCloud\Scenario\Exception\ProcessorException;
1314
use Magento\MagentoCloud\Scenario\Merger;
@@ -111,7 +112,7 @@ public function testExecute(): void
111112
/**
112113
* @throws ProcessorException
113114
*/
114-
public function testExeceuteWithException(): void
115+
public function testExecuteWithException(): void
115116
{
116117
$this->expectException(ProcessorException::class);
117118
$this->expectExceptionMessage('Some error');
@@ -124,7 +125,7 @@ public function testExeceuteWithException(): void
124125

125126
$step1->expects($this->once())
126127
->method('execute')
127-
->willThrowException(new ProcessorException('Some error'));
128+
->willThrowException(new StepException('Some error'));
128129

129130
$steps = [
130131
'step1' => $step1
@@ -155,4 +156,52 @@ public function testExeceuteWithException(): void
155156

156157
$this->processor->execute($scenarios);
157158
}
159+
160+
/**
161+
* @throws ProcessorException
162+
*/
163+
public function testExecuteWithRuntimeException(): void
164+
{
165+
$this->expectException(ProcessorException::class);
166+
$this->expectExceptionMessage('Unhandled error: Some error');
167+
168+
$scenarios = [
169+
'some/scenario.xml'
170+
];
171+
172+
$step1 = $this->getMockForAbstractClass(StepInterface::class);
173+
174+
$step1->expects($this->once())
175+
->method('execute')
176+
->willThrowException(new \RuntimeException('Some error'));
177+
178+
$steps = [
179+
'step1' => $step1
180+
];
181+
182+
$this->packageManagerMock->expects($this->once())
183+
->method('getPrettyInfo')
184+
->willReturn('1.0.0');
185+
$this->mergerMock->expects($this->once())
186+
->method('merge')
187+
->with($scenarios)
188+
->willReturn($steps);
189+
$this->loggerMock->method('info')
190+
->withConsecutive(
191+
[
192+
sprintf(
193+
'Starting scenario(s): %s 1.0.0',
194+
implode(', ', $scenarios)
195+
)
196+
]
197+
);
198+
$this->loggerMock->method('debug')
199+
->withConsecutive(
200+
['Running step: step1']
201+
);
202+
$this->loggerMock->method('error')
203+
->withConsecutive(['Unhandled error: Some error']);
204+
205+
$this->processor->execute($scenarios);
206+
}
158207
}

0 commit comments

Comments
 (0)