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.
This commit is contained in:
Prem Palanisamy committed 2026-05-04 07:51:33 +01:00
1 parent b164631404
commit 39a249231c
1 file changed
+39 -12
+39 -12
View File
@@ -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 = [];
}