From 0f5347c1d3c8707a796fa91c3d6ebfb2baec841f Mon Sep 17 00:00:00 2001 From: Yegor Shytikov Date: Wed, 9 Apr 2025 17:51:54 -0700 Subject: [PATCH 1/3] improve error handling SchemaBuilder Extending error context : Previous: ```Warning: Undefined array key "type" in /var/www/html/magento/vendor/magento/framework/Setup/Declaration/Schema/Db/SchemaBuilder.php on line 91``` Now: ```Warning: Undefined array key "type" in /var/www/html/magento/vendor/magento/framework/Setup/Declaration/Schema/Db/SchemaBuilder.php on line 91 Error processing table catalog_eav_attribute column is_used_in_autocomplete``` Help undersend the issue without heavy debugging! --- .../Declaration/Schema/Db/SchemaBuilder.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/SchemaBuilder.php b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/SchemaBuilder.php index 3395745ca4590..ba44a86045dd7 100644 --- a/lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/SchemaBuilder.php +++ b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/SchemaBuilder.php @@ -87,8 +87,22 @@ public function build(Schema $schema) if (isset($data['table'])) { foreach ($data['table'] as $keyTable => $tableColumns) { foreach ($tableColumns['column'] as $keyColumn => $columnData) { - if ($columnData['type'] == 'json') { - $tablesWithJsonTypeField[$keyTable] = $keyColumn; + try { + if ($columnData['type'] == 'json') { + $tablesWithJsonTypeField[$keyTable] = $keyColumn; + } + } catch (\Throwable $e) { + // Create a new exception with extended context message + $errorMessage = sprintf( + "%s\nError processing table %s column %s", + $e->getMessage(), + $keyTable, + $keyColumn + ); + + // Throw a new exception with the extended message + // This preserves the original error but adds our context + throw new \Exception($errorMessage, $e->getCode(), $e); } } } From f35b25844e7325e216d9f889198ae22bdef73bec Mon Sep 17 00:00:00 2001 From: engcom-Dash Date: Thu, 22 May 2025 17:05:28 +0530 Subject: [PATCH 2/3] Fixed Review Comments & static failures --- .../Declaration/Schema/Db/SchemaBuilder.php | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/SchemaBuilder.php b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/SchemaBuilder.php index 34de09f8c280a..7a55ff922bba7 100644 --- a/lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/SchemaBuilder.php +++ b/lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/SchemaBuilder.php @@ -1,7 +1,7 @@ elementFactory = $elementFactory; $this->dbSchemaReader = $dbSchemaReader; $this->sharding = $sharding; $this->readerComposite = $readerComposite; + $this->logger = $logger; } /** * @inheritdoc * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) + * @throws LocalizedException */ public function build(Schema $schema) { @@ -100,10 +112,10 @@ public function build(Schema $schema) $keyTable, $keyColumn ); - + $this->logger->error($errorMessage); // Throw a new exception with the extended message // This preserves the original error but adds our context - throw new \Exception($errorMessage, $e->getCode(), $e); + throw new LocalizedException(new Phrase($errorMessage)); } } } From 393e74ad2b506d2eb827cc89e64a447dea71abc8 Mon Sep 17 00:00:00 2001 From: engcom-Dash Date: Thu, 22 May 2025 19:48:38 +0530 Subject: [PATCH 3/3] Fixed Unit Tests --- .../Declaration/Schema/Db/SchemaBuilderTest.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/Setup/Test/Unit/Declaration/Schema/Db/SchemaBuilderTest.php b/lib/internal/Magento/Framework/Setup/Test/Unit/Declaration/Schema/Db/SchemaBuilderTest.php index ef3713679846d..838d5f9b6a6fe 100644 --- a/lib/internal/Magento/Framework/Setup/Test/Unit/Declaration/Schema/Db/SchemaBuilderTest.php +++ b/lib/internal/Magento/Framework/Setup/Test/Unit/Declaration/Schema/Db/SchemaBuilderTest.php @@ -1,7 +1,7 @@ elementFactoryMock = $this->getMockBuilder(ElementFactory::class) @@ -401,11 +407,16 @@ public function testBuildHandlesMissingColumnsGracefully() ->method('read') ->willReturn($data); + $this->loggerMock = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $schemaBuilder = new SchemaBuilder( $this->elementFactoryMock, $this->dbSchemaReaderMock, $this->shardingMock, - $readerCompositeMock + $readerCompositeMock, + $this->loggerMock ); $schemaBuilder->build($this->createMock(Schema::class));