From 39a249231c9e2064969040a96bf5a7d56b91ff9d Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 4 May 2026 07:51:33 +0100 Subject: [PATCH] Stop user-data errors leaking to Sentry from migrations Two changes in Destinations/Appwrite.php: 1. Per-resource wrap rethrows non-Migration\Exception throwables. User errors still record on the migration document and the loop continues (existing behaviour). Library bugs and infra failures now bubble to the worker boundary so they can be routed to Sentry instead of being silently absorbed. 2. Row-flush match block catches DuplicateException and StructureException from the database adapter and rethrows them as Migration\Exception so the per-resource wrap above recognises them as user-facing failures. This keeps "Document already exists" / invalid structure messages in the migration report only. --- src/Migration/Destinations/Appwrite.php | 51 +++++++++++++++++++------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/src/Migration/Destinations/Appwrite.php b/src/Migration/Destinations/Appwrite.php index 81ee6b2fda..daaad0a135 100644 --- a/src/Migration/Destinations/Appwrite.php +++ b/src/Migration/Destinations/Appwrite.php @@ -344,6 +344,13 @@ class Appwrite extends Destination previous: $e )); + // User-facing failures (Migration\Exception) are recorded for the migration + // report and the loop continues. Anything else is a library bug or infra + // failure — rethrow so the worker boundary can route it to Sentry. + if (!$e instanceof Exception) { + throw $e; + } + $responseResource = $resource; } finally { $this->dbForProject->setPreserveDates(false); @@ -1074,19 +1081,39 @@ class Appwrite extends Destination } $collectionId = 'database_' . $databaseInternalId . '_collection_' . $tableInternalId; - match ($this->onDuplicate) { - OnDuplicate::Upsert => $dbForDatabases->skipRelationshipsExistCheck( - fn () => $dbForDatabases->upsertDocuments($collectionId, $this->rowBuffer) - ), - OnDuplicate::Skip => $dbForDatabases->skipDuplicates( - fn () => $dbForDatabases->skipRelationshipsExistCheck( + try { + match ($this->onDuplicate) { + OnDuplicate::Upsert => $dbForDatabases->skipRelationshipsExistCheck( + fn () => $dbForDatabases->upsertDocuments($collectionId, $this->rowBuffer) + ), + OnDuplicate::Skip => $dbForDatabases->skipDuplicates( + fn () => $dbForDatabases->skipRelationshipsExistCheck( + fn () => $dbForDatabases->createDocuments($collectionId, $this->rowBuffer) + ) + ), + OnDuplicate::Fail => $dbForDatabases->skipRelationshipsExistCheck( fn () => $dbForDatabases->createDocuments($collectionId, $this->rowBuffer) - ) - ), - OnDuplicate::Fail => $dbForDatabases->skipRelationshipsExistCheck( - fn () => $dbForDatabases->createDocuments($collectionId, $this->rowBuffer) - ), - }; + ), + }; + } catch (DuplicateException $e) { + // Convert to Migration\Exception so the per-resource wrap recognises it + // as a user-facing failure and records it without escalating to Sentry. + throw new Exception( + resourceName: $resource->getName(), + resourceGroup: $resource->getGroup(), + resourceId: $resource->getId(), + message: 'Document already exists', + previous: $e, + ); + } catch (StructureException $e) { + throw new Exception( + resourceName: $resource->getName(), + resourceGroup: $resource->getGroup(), + resourceId: $resource->getId(), + message: $e->getMessage(), + previous: $e, + ); + } } finally { $this->rowBuffer = []; }