Skip to content

Commit 6d3f8dd

Browse files
authored
MCLOUD-6530: Fix an issue with empty error code in the StepException (magento#763)
1 parent 05fcd40 commit 6d3f8dd

File tree

8 files changed

+83
-19
lines changed

8 files changed

+83
-19
lines changed

config/schema.error.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,12 @@
331331
suggestion: 'Support for the Braintree module is no longer included with Magento 2.4.0 and later. Remove the CONFIG__STORES__DEFAULT__PAYMENT__BRAINTREE__CHANNEL variable from the variables section of the .magento.app.yaml file. For Braintree support, use an official Braintree Payments extension from the Magento Marketplace instead.'
332332
stage: deploy
333333
type: critical
334+
!php/const Magento\MagentoCloud\App\Error::DEPLOY_WRONG_SEARCH_ENGINE:
335+
step: validate-config
336+
title: 'Magento 2.4.0 requires Elasticsearch service to be installed'
337+
suggestion: 'Install Elasticsearch service'
338+
stage: deploy
339+
type: critical
334340
!php/const Magento\MagentoCloud\App\Error::PD_DEPLOY_IS_FAILED:
335341
step: is-deploy-failed
336342
title: 'Deploy stage failed'

dist/error-codes.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
1+
<!-Note: The error code tables in this file are auto-generated from source code. To request changes to error code descriptions or suggestions, submit a GitHub issue to the magento/ece-tools repository.->
22

33
## Critical Errors
44

5+
Critical errors indicate a problem with the Magento Commerce Cloud project configuration that causes deployment failure, for example incorrect, unsupported, or missing configuration for required settings. Before you can deploy, you must update the configuration to resolve these errors.
56

67
### Build stage
78

89
{:.error-table}
9-
| Error code | Build step | Error description | Suggested action |
10+
| Error code | Build step | Error description (Title) | Suggested action |
1011
| - | - | - | - |
1112
| 2 | | Cannot write to the `./app/etc/env.php` file | Deployment script cannot make required changes to the `/app/etc/env.php` file. Check your filesystem permissions. |
1213
| 3 | | Configuration isn't defined in the `schema.yaml` file | Configuration is not defined in the `./vendor/magento/ece-tools/config/schema.yaml` file. Check that the config variable name is correct, and that it is defined. |
@@ -37,7 +38,7 @@
3738
### Deploy stage
3839

3940
{:.error-table}
40-
| Error code | Deploy step | Error description | Suggested action |
41+
| Error code | Deploy step | Error description (Title) | Suggested action |
4142
| - | - | - | - |
4243
| 101 | pre-deploy: cache | Incorrect cache configuration (missing port or host) | Cache configuration is missing required parameters `server` or `port`. Check the `cloud.log` for more information. |
4344
| 102 | | Cannot write to the `./app/etc/env.php` file | Deployment script cannot make required changes to the `/app/etc/env.php` file. Check your filesystem permissions. |
@@ -72,11 +73,12 @@
7273
| 131 | install-update | The `crypt/key` key value does not exist in the `./app/etc/env.php` file or the `CRYPT_KEY` cloud environment variable | This error occurs if the `./app/etc/env.php` file is not present when Magento deployment begins, or if the `crypt/key` value is undefined. If you migrated the database from another environment, retrieve the crypt key value from that environment. Then, add the value to the [CRYPT_KEY](https://devdocs.magento.com/cloud/env/variables-deploy.html#crypt_key) cloud environment variable in your current environment. See [Add the Magento encryption key](https://devdocs.magento.com/cloud/setup/first-time-setup-import-import.html#encryption-key). If you accidentally removed the `./app/etc/env.php` file, use the following command to restore it from the backup files created from a previous deployment: `./vendor/bin/ece-tools backup:restore` CLI command ." |
7374
| 132 | | Can not connect to the Elasticsearch service | Check that credentials for elasticsearch are correct and service is running |
7475
| 133 | validate-config | Remove Magento Braintree module configuration which is no longer supported in Magento 2.4 and later versions. | Support for the Braintree module is no longer included with Magento 2.4.0 and later. Remove the CONFIG__STORES__DEFAULT__PAYMENT__BRAINTREE__CHANNEL variable from the variables section of the .magento.app.yaml file. For Braintree support, use an official Braintree Payments extension from the Magento Marketplace instead. |
76+
| 134 | validate-config | Magento 2.4.0 requires Elasticsearch service to be installed | Install Elasticsearch service |
7577

7678
### Post-deploy stage
7779

7880
{:.error-table}
79-
| Error code | Post-deploy step | Error description | Suggested action |
81+
| Error code | Post-deploy step | Error description (Title) | Suggested action |
8082
| - | - | - | - |
8183
| 201 | is-deploy-failed | Deploy stage failed | |
8284
| 202 | | The `./app/etc/env.php` file is not writable | Deployment script cannot make required changes to the `/app/etc/env.php` file. Check your filesystem permissions. |
@@ -91,21 +93,21 @@
9193
### General
9294

9395
{:.error-table}
94-
| Error code | General step | Error description | Suggested action |
96+
| Error code | General step | Error description (Title) | Suggested action |
9597
| - | - | - | - |
9698
| 243 | | Configuration is not defined in the `schema.yaml` file | Check that the config variable name is correct, and that it defined. |
9799
| 244 | | Failed to parse the `.magento.env.yaml` file | The `./.magento.env.yaml` file format is invalid. Use a YAML parser to check the syntax and fix any errors. |
98100
| 245 | | Unable to read the `.magento.env.yaml` file | Unable to read the `./.magento.env.yaml` file. Check file permissions. |
99101
| 246 | | Unable to read the `.schema.yaml` file | |
100102

101-
102103
## Warning Errors
103104

105+
Warning errors indicate a problem with the Magento Commerce Cloud project configuration such as incorrect, deprecated, unsupported, or missing configuration settings for optional features that can affect site operation. Although a warning does not cause deployment failure, you should review warning messages and update the configuration to resolve them.
104106

105107
### Build stage
106108

107109
{:.error-table}
108-
| Error code | Build step | Error description | Suggested action |
110+
| Error code | Build step | Error description (Title) | Suggested action |
109111
| - | - | - | - |
110112
| 1001 | validate-config | File app/etc/config.php does not exist | |
111113
| 1002 | validate-config | The ./build_options.ini file is no longer supported | |
@@ -118,7 +120,7 @@
118120
### Deploy stage
119121

120122
{:.error-table}
121-
| Error code | Deploy step | Error description | Suggested action |
123+
| Error code | Deploy step | Error description (Title) | Suggested action |
122124
| - | - | - | - |
123125
| 2001 | pre-deploy:cache | Cache is configured for a Redis service that is not available. Configuration will be ignored. | |
124126
| 2002 | validate-config | The configured state is not ideal | |
@@ -149,7 +151,7 @@
149151
### Post-deploy stage
150152

151153
{:.error-table}
152-
| Error code | Post-deploy step | Error description | Suggested action |
154+
| Error code | Post-deploy step | Error description (Title) | Suggested action |
153155
| - | - | - | - |
154156
| 3001 | validate-config | Debug logging is enabled in Magento | To save disk space, do not enable debug logging for your production environments. |
155157
| 3002 | warm-up | Can not fetch store urls | |
@@ -158,7 +160,7 @@
158160
### General
159161

160162
{:.error-table}
161-
| Error code | General step | Error description | Suggested action |
163+
| Error code | General step | Error description (Title) | Suggested action |
162164
| - | - | - | - |
163165
| 4001 | | Can not get system processor count: | |
164166

src/App/Error.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
class Error
1414
{
15+
public const DEFAULT_ERROR = 1;
16+
1517
public const BUILD_ENV_PHP_IS_NOT_WRITABLE = 2;
1618
public const BUILD_CONFIG_NOT_DEFINED = 3;
1719
public const BUILD_CONFIG_PARSE_FAILED = 4;
@@ -71,6 +73,7 @@ class Error
7173
public const DEPLOY_CRYPT_KEY_IS_ABSENT = 131;
7274
public const DEPLOY_ES_CANNOT_CONNECT = 132;
7375
public const DEPLOY_WRONG_BRAINTREE_VARIABLE = 133;
76+
public const DEPLOY_WRONG_SEARCH_ENGINE = 134;
7477

7578
public const PD_DEPLOY_IS_FAILED = 201;
7679
public const PD_ENV_PHP_IS_NOT_WRITABLE = 202;

src/Command/Dev/GenerateSchemaError.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,21 @@ private function groupErrors(array $errors): array
124124
*/
125125
private function generateDocs(array $errors): string
126126
{
127-
$result = '';
127+
$result = '<!-Note: The error code tables in this file are auto-generated from source code. ' .
128+
'To request changes to error code descriptions or suggestions, ' .
129+
'submit a GitHub issue to the magento/ece-tools repository.->';
130+
$result .= "\n";
128131

129132
foreach ($errors as $type => $typeErrors) {
130-
$result .= sprintf("\n\n## %s Errors\n\n", ucfirst($type));
133+
$result .= sprintf("\n## %s Errors\n", ucfirst($type));
134+
$result .= sprintf("\n%s\n", $this->getErrorTypeDescription()[$type]);
131135

132136
foreach ($typeErrors as $stage => $stageErrors) {
133-
$result .= sprintf("\n### %s%s\n\n", ucfirst($stage), $stage === 'general' ? '' : ' stage');
137+
$result .= sprintf("\n### %s%s\n", ucfirst($stage), $stage === 'general' ? '' : ' stage');
134138

135-
$table = "{:.error-table}\n";
139+
$table = "\n{:.error-table}\n";
136140
$table .= sprintf(
137-
"| Error code | %s step | Error description | Suggested action |\n",
141+
"| Error code | %s step | Error description (Title) | Suggested action |\n",
138142
ucfirst($stage)
139143
);
140144
$table .= "| - | - | - | - |\n";
@@ -154,4 +158,22 @@ private function generateDocs(array $errors): string
154158

155159
return $result . self::FOOTER_SCRIPTS;
156160
}
161+
162+
/**
163+
* Returns an array of error types description (warning and critical)
164+
*
165+
* @return array
166+
*/
167+
public function getErrorTypeDescription(): array
168+
{
169+
return [
170+
'critical' => 'Critical errors indicate a problem with the Magento Commerce Cloud project configuration ' .
171+
'that causes deployment failure, for example incorrect, unsupported, or missing configuration for ' .
172+
'required settings. Before you can deploy, you must update the configuration to resolve these errors.',
173+
'warning' => 'Warning errors indicate a problem with the Magento Commerce Cloud project configuration ' .
174+
'such as incorrect, deprecated, unsupported, or missing configuration settings for optional features ' .
175+
'that can affect site operation. Although a warning does not cause deployment failure, you ' .
176+
'should review warning messages and update the configuration to resolve them.',
177+
];
178+
}
157179
}

src/Config/Validator/Deploy/ElasticSearchIntegrity.php

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

88
namespace Magento\MagentoCloud\Config\Validator\Deploy;
99

10+
use Magento\MagentoCloud\App\Error;
1011
use Magento\MagentoCloud\Config\Validator;
1112
use Magento\MagentoCloud\Config\ValidatorException;
1213
use Magento\MagentoCloud\Config\ValidatorInterface;
14+
use Magento\MagentoCloud\Filesystem\FileSystemException;
1315
use Magento\MagentoCloud\Package\MagentoVersion;
1416
use Magento\MagentoCloud\Package\UndefinedPackageException;
1517
use Magento\MagentoCloud\Service\ElasticSearch;
@@ -58,9 +60,9 @@ public function validate(): Validator\ResultInterface
5860
if ($this->magentoVersion->isGreaterOrEqual('2.4.0')
5961
&& !$this->elasticsearch->isInstalled()
6062
) {
61-
return $this->resultFactory->error('Magento 2.4.0 requires Elasticsearch service to be installed.');
63+
return $this->resultFactory->errorByCode(Error::DEPLOY_WRONG_SEARCH_ENGINE);
6264
}
63-
} catch (UndefinedPackageException $exception) {
65+
} catch (UndefinedPackageException | FileSystemException $exception) {
6466
throw new ValidatorException($exception->getMessage(), $exception->getCode(), $exception);
6567
}
6668

src/Step/ValidateConfiguration.php

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

88
namespace Magento\MagentoCloud\Step;
99

10+
use Magento\MagentoCloud\App\Error as AppError;
1011
use Magento\MagentoCloud\App\Logger;
1112
use Magento\MagentoCloud\Config\Validator\Result\Error;
1213
use Magento\MagentoCloud\Config\ValidatorException;
@@ -65,7 +66,7 @@ public function execute(): void
6566

6667
if ($level >= ValidatorInterface::LEVEL_CRITICAL) {
6768
$error = array_values($levelErrors)[0];
68-
throw new StepException($error->getError(), $error->getErrorCode());
69+
throw new StepException($error->getError(), $error->getErrorCode() ?: AppError::DEFAULT_ERROR);
6970
}
7071
}
7172
}

src/Test/Unit/Config/Validator/Deploy/ElasticsearchIntegrityTest.php

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

88
namespace Magento\MagentoCloud\Test\Unit\Config\Validator\Deploy;
99

10+
use Magento\MagentoCloud\App\Error;
1011
use Magento\MagentoCloud\Config\Validator\Deploy\ElasticSearchIntegrity;
1112
use Magento\MagentoCloud\Config\Validator\ResultFactory;
1213
use Magento\MagentoCloud\Config\ValidatorException;
@@ -84,7 +85,8 @@ public function testValidateNoElasticSearch(): void
8485
->method('isInstalled')
8586
->willReturn(false);
8687
$this->resultFactoryMock->expects($this->once())
87-
->method('error');
88+
->method('errorByCode')
89+
->with(Error::DEPLOY_WRONG_SEARCH_ENGINE);
8890

8991
$this->validator->validate();
9092
}

src/Test/Unit/Step/ValidateConfigurationTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\MagentoCloud\Test\Unit\Step;
99

10+
use Magento\MagentoCloud\App\Error;
1011
use Magento\MagentoCloud\App\Logger;
1112
use Magento\MagentoCloud\Config\Validator\Result;
1213
use Magento\MagentoCloud\Config\ValidatorInterface;
@@ -90,6 +91,31 @@ public function testExecuteWithCriticalError(): void
9091
$step->execute();
9192
}
9293

94+
/**
95+
* @throws StepException
96+
*/
97+
public function testExecuteWithCriticalErrorAndEmptyErrorCode(): void
98+
{
99+
$this->expectException(StepException::class);
100+
$this->expectExceptionMessage('some error');
101+
$this->expectExceptionCode(Error::DEFAULT_ERROR);
102+
103+
$this->loggerMock->expects($this->once())
104+
->method('log')
105+
->with(ValidatorInterface::LEVEL_CRITICAL, 'some error');
106+
107+
$step = new ValidateConfiguration(
108+
$this->loggerMock,
109+
[
110+
ValidatorInterface::LEVEL_CRITICAL => [
111+
$this->createValidatorWithError('some error', 'some suggestion'),
112+
],
113+
]
114+
);
115+
116+
$step->execute();
117+
}
118+
93119
/**
94120
* @throws StepException
95121
*/

0 commit comments

Comments
 (0)