mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
spike: convert worker throws to AppwriteException + isPublishable gate
This commit is contained in:
@@ -346,6 +346,10 @@ class Exception extends \Exception
|
||||
public const string MIGRATION_IN_PROGRESS = 'migration_in_progress';
|
||||
public const string MIGRATION_PROVIDER_ERROR = 'migration_provider_error';
|
||||
public const string MIGRATION_DATABASE_TYPE_UNSUPPORTED = 'migration_database_type_unsupported';
|
||||
public const string MIGRATION_SOURCE_PROJECT_ID_REQUIRED = 'migration_source_project_id_required';
|
||||
public const string MIGRATION_SOURCE_PROJECT_NOT_FOUND = 'migration_source_project_not_found';
|
||||
public const string MIGRATION_SOURCE_TYPE_INVALID = 'migration_source_type_invalid';
|
||||
public const string MIGRATION_DESTINATION_TYPE_INVALID = 'migration_destination_type_invalid';
|
||||
|
||||
/** Realtime */
|
||||
public const string REALTIME_MESSAGE_FORMAT_INVALID = 'realtime_message_format_invalid';
|
||||
|
||||
@@ -196,13 +196,13 @@ class Migrations extends Action
|
||||
$projectDB = null;
|
||||
$useAppwriteApiSource = false;
|
||||
if ($source === SourceAppwrite::getName() && empty($credentials['projectId'])) {
|
||||
throw new MigrationException('', '', message: 'Source projectId is required for Appwrite migrations', code: MigrationException::CODE_VALIDATION);
|
||||
throw new Exception(Exception::MIGRATION_SOURCE_PROJECT_ID_REQUIRED);
|
||||
}
|
||||
|
||||
if (! empty($credentials['projectId'])) {
|
||||
$this->sourceProject = $this->dbForPlatform->getDocument('projects', $credentials['projectId']);
|
||||
if ($this->sourceProject->isEmpty()) {
|
||||
throw new MigrationException('', '', message: 'Source project not found for provided projectId', code: MigrationException::CODE_NOT_FOUND);
|
||||
throw new Exception(Exception::MIGRATION_SOURCE_PROJECT_NOT_FOUND);
|
||||
}
|
||||
|
||||
$sourceRegion = $this->sourceProject->getAttribute('region', 'default');
|
||||
@@ -265,7 +265,7 @@ class Migrations extends Action
|
||||
$this->deviceForMigrations,
|
||||
$this->dbForProject,
|
||||
),
|
||||
default => throw new MigrationException('', '', message: 'Invalid source type', code: MigrationException::CODE_VALIDATION),
|
||||
default => throw new Exception(Exception::MIGRATION_SOURCE_TYPE_INVALID),
|
||||
};
|
||||
|
||||
$resources = $migration->getAttribute('resources', []);
|
||||
@@ -310,7 +310,7 @@ class Migrations extends Action
|
||||
$options['filename'],
|
||||
$options['columns'] ?? [],
|
||||
),
|
||||
default => throw new MigrationException('', '', message: 'Invalid destination type', code: MigrationException::CODE_VALIDATION),
|
||||
default => throw new Exception(Exception::MIGRATION_DESTINATION_TYPE_INVALID),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -538,8 +538,18 @@ class Migrations extends Action
|
||||
|
||||
$caughtError = $th;
|
||||
|
||||
// MigrationException is reserved for user-facing failures and stays in the migration report only.
|
||||
if (!$th instanceof MigrationException) {
|
||||
// Mirror general.php's HTTP-error pattern: typed AppwriteException uses its
|
||||
// registry-driven isPublishable() flag; library-thrown Migration\Exception is
|
||||
// always user-facing; anything else falls back to the code heuristic.
|
||||
if ($th instanceof Exception) {
|
||||
$publish = $th->isPublishable();
|
||||
} elseif ($th instanceof MigrationException) {
|
||||
$publish = false;
|
||||
} else {
|
||||
$publish = $th->getCode() === 0 || $th->getCode() >= 500;
|
||||
}
|
||||
|
||||
if ($publish) {
|
||||
call_user_func($this->logError, $th, 'appwrite-worker', 'appwrite-queue-' . self::getName(), [
|
||||
'migrationId' => $migration->getId(),
|
||||
'source' => $migration->getAttribute('source') ?? '',
|
||||
|
||||
Reference in New Issue
Block a user