Skip to content

Commit fea0ee7

Browse files
authored
MCLOUD-7457: update exit code when error occurs in build:custom:compose (#31)
1 parent 761e44c commit fea0ee7

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

src/Command/Image/GenerateEs.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\CloudDocker\Cli;
1111
use Magento\CloudDocker\Filesystem\DirectoryList;
12+
use Magento\CloudDocker\Filesystem\FileNotFoundException;
1213
use Magento\CloudDocker\Filesystem\Filesystem;
1314
use Symfony\Component\Console\Command\Command;
1415
use Symfony\Component\Console\Input\InputInterface;
@@ -93,6 +94,8 @@ protected function configure(): void
9394
* Generates data for elasticsearch images.
9495
*
9596
* {@inheritDoc}
97+
* @throws FileNotFoundException
98+
* @throws \Magento\CloudDocker\Filesystem\FileSystemException
9699
*/
97100
public function execute(InputInterface $input, OutputInterface $output): int
98101
{

src/Command/Image/GeneratePhp.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
use Composer\Semver\Semver;
1111
use Magento\CloudDocker\App\ConfigurationMismatchException;
1212
use Magento\CloudDocker\Cli;
13-
use Magento\CloudDocker\Filesystem\FileNotFoundException;
14-
use Magento\CloudDocker\Filesystem\Filesystem;
1513
use Magento\CloudDocker\Compose\Php\ExtensionResolver;
1614
use Magento\CloudDocker\Filesystem\DirectoryList;
15+
use Magento\CloudDocker\Filesystem\FileNotFoundException;
16+
use Magento\CloudDocker\Filesystem\Filesystem;
1717
use Symfony\Component\Console\Command\Command;
1818
use Symfony\Component\Console\Input\InputArgument;
1919
use Symfony\Component\Console\Input\InputInterface;
@@ -132,6 +132,7 @@ protected function configure(): void
132132
*
133133
* @throws ConfigurationMismatchException
134134
* @throws FileNotFoundException
135+
* @throws \Magento\CloudDocker\Filesystem\FileSystemException
135136
*/
136137
public function execute(InputInterface $input, OutputInterface $output): int
137138
{
@@ -160,6 +161,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
160161
* @param string $edition
161162
* @throws ConfigurationMismatchException
162163
* @throws FileNotFoundException
164+
* @throws \Magento\CloudDocker\Filesystem\FileSystemException
163165
*/
164166
private function build(string $version, string $edition): void
165167
{

src/Config/Dist/Generator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ private function generateByServices(Config $config): array
120120
*
121121
* @param string $filePath
122122
* @param array $config
123+
* @throws FileSystemException
123124
*/
124125
private function saveConfigDist(string $filePath, array $config): void
125126
{
@@ -140,6 +141,7 @@ private function saveConfigDist(string $filePath, array $config): void
140141
* @param array $config
141142
*
142143
* @throws ConfigurationMismatchException
144+
* @throws FileSystemException
143145
*/
144146
private function saveConfigEnv(string $filePath, array $config): void
145147
{

src/Filesystem/Filesystem.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,25 @@
1515
class Filesystem
1616
{
1717
/**
18-
* Write the contents of a file.
18+
* Write contents to file in given path
1919
*
2020
* @param string $path
21-
* @param string $contents
22-
* @return int|bool
21+
* @param string $content
22+
* @return int The number of bytes that were written.
23+
* @throws FileSystemException In case if can write content into file
2324
*/
24-
public function put($path, $contents)
25+
public function put($path, $content)
2526
{
26-
return file_put_contents($path, $contents);
27+
$result = @file_put_contents($path, $content);
28+
if (!$result) {
29+
throw new FilesystemException(sprintf(
30+
'The specified "%s" file could not be written %s',
31+
$path,
32+
$this->getWarningMessage()
33+
));
34+
}
35+
36+
return $result;
2737
}
2838

2939
/**
@@ -241,4 +251,19 @@ public function chmod(string $path, int $mode): bool
241251
{
242252
return chmod($path, $mode);
243253
}
254+
255+
/**
256+
* Returns last warning message string
257+
*
258+
* @return string|null
259+
*/
260+
private function getWarningMessage()
261+
{
262+
$warning = error_get_last();
263+
if ($warning && $warning['type'] == E_WARNING) {
264+
return 'Warning!' . $warning['message'];
265+
}
266+
267+
return null;
268+
}
244269
}

0 commit comments

Comments
 (0)