Skip to content

Commit bbad0dc

Browse files
ENGCOM-5187: Add more descriptive exception when data patch fails to apply. #23046
- Merge Pull Request #23046 from ashsmith/magento2:data-patch-exception - Merged commits: 1. 199887d 2. c0d920d
2 parents 19fab05 + c0d920d commit bbad0dc

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

lib/internal/Magento/Framework/Setup/Patch/PatchApplier.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Framework\Module\ModuleList;
1111
use Magento\Framework\ObjectManagerInterface;
1212
use Magento\Framework\Phrase;
13-
use Magento\Framework\Setup\Exception;
13+
use Magento\Framework\Setup\Exception as SetupException;
1414
use Magento\Framework\Setup\ModuleDataSetupInterface;
1515

1616
/**
@@ -129,8 +129,8 @@ public function __construct(
129129
/**
130130
* Apply all patches for one module
131131
*
132-
* @param null | string $moduleName
133-
* @throws Exception
132+
* @param null|string $moduleName
133+
* @throws SetupException
134134
*/
135135
public function applyDataPatch($moduleName = null)
136136
{
@@ -149,7 +149,7 @@ public function applyDataPatch($moduleName = null)
149149
['moduleDataSetup' => $this->moduleDataSetup]
150150
);
151151
if (!$dataPatch instanceof DataPatchInterface) {
152-
throw new Exception(
152+
throw new SetupException(
153153
new Phrase("Patch %1 should implement DataPatchInterface", [get_class($dataPatch)])
154154
);
155155
}
@@ -164,7 +164,17 @@ public function applyDataPatch($moduleName = null)
164164
$this->moduleDataSetup->getConnection()->commit();
165165
} catch (\Exception $e) {
166166
$this->moduleDataSetup->getConnection()->rollBack();
167-
throw new Exception(new Phrase($e->getMessage()));
167+
throw new SetupException(
168+
new Phrase(
169+
'Unable to apply data patch %1 for module %2. Original exception message: %3',
170+
[
171+
get_class($dataPatch),
172+
$moduleName,
173+
$e->getMessage()
174+
]
175+
),
176+
$e
177+
);
168178
} finally {
169179
unset($dataPatch);
170180
}
@@ -173,8 +183,7 @@ public function applyDataPatch($moduleName = null)
173183
}
174184

175185
/**
176-
* Register all patches in registry in order to manipulate chains and dependencies of patches
177-
* of patches
186+
* Register all patches in registry in order to manipulate chains and dependencies of patches of patches
178187
*
179188
* @param string $moduleName
180189
* @param string $patchType
@@ -207,8 +216,8 @@ private function prepareRegistry($moduleName, $patchType)
207216
*
208217
* Please note: that schema patches are not revertable
209218
*
210-
* @param null | string $moduleName
211-
* @throws Exception
219+
* @param null|string $moduleName
220+
* @throws SetupException
212221
*/
213222
public function applySchemaPatch($moduleName = null)
214223
{
@@ -229,7 +238,7 @@ public function applySchemaPatch($moduleName = null)
229238
$schemaPatch->apply();
230239
$this->patchHistory->fixPatch(get_class($schemaPatch));
231240
} catch (\Exception $e) {
232-
throw new Exception(
241+
throw new SetupException(
233242
new Phrase(
234243
'Unable to apply patch %1 for module %2. Original exception message: %3',
235244
[
@@ -248,8 +257,8 @@ public function applySchemaPatch($moduleName = null)
248257
/**
249258
* Revert data patches for specific module
250259
*
251-
* @param null | string $moduleName
252-
* @throws Exception
260+
* @param null|string $moduleName
261+
* @throws SetupException
253262
*/
254263
public function revertDataPatches($moduleName = null)
255264
{
@@ -270,7 +279,7 @@ public function revertDataPatches($moduleName = null)
270279
$adapter->commit();
271280
} catch (\Exception $e) {
272281
$adapter->rollBack();
273-
throw new Exception(new Phrase($e->getMessage()));
282+
throw new SetupException(new Phrase($e->getMessage()));
274283
} finally {
275284
unset($dataPatch);
276285
}

0 commit comments

Comments
 (0)