1
0
Fork 0
mirror of synced 2024-06-03 03:14:50 +12:00

Merge pull request #7555 from appwrite/fix-catch-exception

Replace catching \Exception with \Throwable
This commit is contained in:
Jake Barnby 2024-02-13 17:01:05 +13:00 committed by GitHub
commit a688929488
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 39 additions and 48 deletions

View file

@ -77,7 +77,7 @@ CLI::setResource('dbForConsole', function ($pools, $cache) {
}
$ready = true;
} catch (\Exception $err) {
} catch (\Throwable $err) {
Console::warning($err->getMessage());
$pools->get('console')->reclaim();
sleep($sleep);

View file

@ -506,7 +506,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
if (!empty($state)) {
try {
$state = \array_merge($defaultState, $oauth2->parseState($state));
} catch (\Exception $exception) {
} catch (\Throwable $exception) {
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to parse login state params as passed from OAuth2 provider');
}
} else {

View file

@ -291,7 +291,7 @@ App::get('/v1/avatars/image')
try {
$image = new Image($fetch);
} catch (\Exception $exception) {
} catch (\Throwable $exception) {
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Unable to parse image');
}

View file

@ -150,7 +150,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att
throw new Exception(Exception::ATTRIBUTE_ALREADY_EXISTS);
} catch (LimitException) {
throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED, 'Attribute limit exceeded');
} catch (\Exception $e) {
} catch (\Throwable $e) {
$dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $collectionId);
$dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $collection->getInternalId());
throw $e;
@ -194,7 +194,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att
} catch (LimitException) {
$dbForProject->deleteDocument('attributes', $attribute->getId());
throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED, 'Attribute limit exceeded');
} catch (\Exception $e) {
} catch (\Throwable $e) {
$dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $relatedCollection->getId());
$dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $relatedCollection->getInternalId());
throw $e;

View file

@ -733,7 +733,7 @@ App::get('/v1/health/anti-virus')
try {
$output['version'] = @$antivirus->version();
$output['status'] = (@$antivirus->ping()) ? 'pass' : 'fail';
} catch (\Exception $e) {
} catch (\Throwable $e) {
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Antivirus is not available');
}
}

View file

@ -617,7 +617,7 @@ App::get('/v1/migrations/firebase/report/oauth')
try {
$report = $firebase->report($resources);
} catch (\Exception $e) {
} catch (\Throwable $e) {
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Source Error: ' . $e->getMessage());
}
@ -829,7 +829,7 @@ App::get('/v1/migrations/firebase/projects')
if ($isExpired) {
try {
$firebase->refreshTokens($refreshToken);
} catch (\Exception $e) {
} catch (\Throwable $e) {
throw new Exception(Exception::USER_IDENTITY_NOT_FOUND);
}
@ -859,7 +859,7 @@ App::get('/v1/migrations/firebase/projects')
'projectId' => $project['projectId'],
];
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
throw new Exception(Exception::USER_IDENTITY_NOT_FOUND);
}

View file

@ -91,7 +91,7 @@ App::post('/v1/proxy/rules')
try {
$domain = new Domain($domain);
} catch (\Exception) {
} catch (\Throwable) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Domain may not start with http:// or https://.');
}

View file

@ -1068,7 +1068,7 @@ App::delete('/v1/teams/:teamId/memberships/:membershipId')
$dbForProject->deleteDocument('memberships', $membership->getId());
} catch (AuthorizationException $exception) {
throw new Exception(Exception::USER_UNAUTHORIZED);
} catch (\Exception $exception) {
} catch (\Throwable $exception) {
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove membership from DB');
}

View file

@ -77,7 +77,7 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) {
$dbForConsole = $app->getResource('dbForConsole');
/** @var Utopia\Database\Database $dbForConsole */
break; // leave the do-while if successful
} catch (\Exception $e) {
} catch (\Throwable $e) {
Console::warning("Database not ready. Retrying connection ({$attempts})...");
if ($attempts >= $max) {
throw new \Exception('Failed to connect to database: ' . $e->getMessage());
@ -91,7 +91,7 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) {
try {
Console::success('[Setup] - Creating database: appwrite...');
$dbForConsole->create();
} catch (\Exception $e) {
} catch (\Throwable $e) {
Console::success('[Setup] - Skip: metadata table already exists');
}

View file

@ -1410,7 +1410,7 @@ function getDevice($root): Device
$accessSecret = $dsn->getPassword() ?? '';
$bucket = $dsn->getPath() ?? '';
$region = $dsn->getParam('region');
} catch (\Exception $e) {
} catch (\Throwable $e) {
Console::warning($e->getMessage() . 'Invalid DSN. Defaulting to Local device.');
}

View file

@ -246,7 +246,7 @@ try {
'workerName' => strtolower($workerName) ?? null,
'queueName' => $queueName
]);
} catch (\Exception $e) {
} catch (\Throwable $e) {
Console::error($e->getMessage() . ', File: ' . $e->getFile() . ', Line: ' . $e->getLine());
}

View file

@ -279,7 +279,7 @@ class Firebase extends OAuth2
$role = \json_decode($role, true);
return $role;
} catch (\Exception $e) {
} catch (\Throwable $e) {
if ($e->getCode() !== 404) {
throw $e;
}

View file

@ -401,7 +401,7 @@ abstract class Migration
try {
$stmt->execute();
} catch (\Exception $e) {
} catch (\Throwable $e) {
Console::warning($e->getMessage());
}
}

View file

@ -2,7 +2,6 @@
namespace Appwrite\Platform\Tasks;
use Exception;
use League\Csv\CannotInsertRecord;
use Utopia\App;
use Utopia\Database\Document;
@ -200,7 +199,7 @@ class CalcTierStats extends Action
$mail->Body = "Please find the daily cloud report atttached";
$mail->send();
Console::success('Email has been sent!');
} catch (Exception $e) {
} catch (\Throwable $e) {
Console::error("Message could not be sent. Mailer Error: {$mail->ErrorInfo}");
}
}

View file

@ -2,7 +2,6 @@
namespace Appwrite\Platform\Tasks;
use Exception;
use League\Csv\CannotInsertRecord;
use Utopia\App;
use Utopia\Platform\Action;
@ -180,7 +179,7 @@ class GetMigrationStats extends Action
$mail->Body = "Please find the migration report atttached";
$mail->send();
Console::success('Email has been sent!');
} catch (Exception $e) {
} catch (\Throwable $e) {
Console::error("Message could not be sent. Mailer Error: {$mail->ErrorInfo}");
}
}

View file

@ -3,7 +3,6 @@
namespace Appwrite\Platform\Tasks;
use Appwrite\Event\Hamster as EventHamster;
use Exception;
use Utopia\App;
use Utopia\Platform\Action;
use Utopia\CLI\Console;
@ -120,7 +119,7 @@ class Hamster extends Action
->setType(EventHamster::TYPE_ORGANISATION)
->setOrganization($organization)
->trigger();
} catch (Exception $e) {
} catch (\Throwable $e) {
Console::error($e->getMessage());
}
});
@ -135,7 +134,7 @@ class Hamster extends Action
->setType(EventHamster::TYPE_PROJECT)
->setProject($project)
->trigger();
} catch (Exception $e) {
} catch (\Throwable $e) {
Console::error($e->getMessage());
}
});
@ -150,7 +149,7 @@ class Hamster extends Action
->setType(EventHamster::TYPE_USER)
->setUser($user)
->trigger();
} catch (Exception $e) {
} catch (\Throwable $e) {
Console::error($e->getMessage());
}
});

View file

@ -18,8 +18,6 @@ use Appwrite\SDK\Language\Python;
use Appwrite\SDK\Language\REST;
use Appwrite\SDK\Language\Ruby;
use Appwrite\SDK\Language\Swift;
use Exception;
use Throwable;
use Appwrite\SDK\Language\Apple;
use Appwrite\SDK\Language\Web;
use Appwrite\SDK\SDK;
@ -242,9 +240,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
try {
$sdk->generate($result);
} catch (Exception $exception) {
Console::error($exception->getMessage());
} catch (Throwable $exception) {
} catch (\Throwable $exception) {
Console::error($exception->getMessage());
}

View file

@ -8,7 +8,6 @@ use Appwrite\Event\Usage;
use Appwrite\Messaging\Adapter\Realtime;
use Appwrite\Utopia\Response\Model\Deployment;
use Appwrite\Vcs\Comment;
use Exception;
use Swoole\Coroutine as Co;
use Executor\Executor;
use Utopia\App;
@ -420,7 +419,7 @@ class Builds extends Action
variables: $vars,
command: $command
);
} catch (Exception $error) {
} catch (\Throwable $error) {
$err = $error;
}
}),
@ -459,7 +458,7 @@ class Builds extends Action
}
}
);
} catch (Exception $error) {
} catch (\Throwable $error) {
if (empty($err)) {
$err = $error;
}
@ -617,7 +616,7 @@ class Builds extends Action
'$id' => $commentId
]));
break;
} catch (Exception $err) {
} catch (\Throwable $err) {
if ($retries >= 9) {
throw $err;
}

View file

@ -165,7 +165,7 @@ class Databases extends Action
}
$dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available'));
} catch (\Exception $e) {
} catch (\Throwable $e) {
// TODO: Send non DatabaseExceptions to Sentry
Console::error($e->getMessage());
@ -269,7 +269,7 @@ class Databases extends Action
if (!$relatedAttribute->isEmpty()) {
$dbForProject->deleteDocument('attributes', $relatedAttribute->getId());
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
// TODO: Send non DatabaseExceptions to Sentry
Console::error($e->getMessage());
@ -397,7 +397,7 @@ class Databases extends Action
throw new DatabaseException('Failed to create Index');
}
$dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'available'));
} catch (\Exception $e) {
} catch (\Throwable $e) {
// TODO: Send non DatabaseExceptions to Sentry
Console::error($e->getMessage());
@ -455,7 +455,7 @@ class Databases extends Action
}
$dbForProject->deleteDocument('indexes', $index->getId());
$index->setAttribute('status', 'deleted');
} catch (\Exception $e) {
} catch (\Throwable $e) {
// TODO: Send non DatabaseExceptions to Sentry
Console::error($e->getMessage());

View file

@ -11,7 +11,6 @@ use Utopia\Audit\Audit;
use Utopia\Cache\Adapter\Filesystem;
use Utopia\Cache\Cache;
use Utopia\Database\Database;
use Exception;
use Utopia\App;
use Utopia\CLI\Console;
use Utopia\Database\DateTime;
@ -585,7 +584,7 @@ class Deletes extends Action
// Delete metadata tables
try {
$dbForProject->deleteCollection('_metadata');
} catch (Exception) {
} catch (\Throwable) {
// Ignore: deleteCollection tries to delete a metadata entry after the collection is deleted,
// which will throw an exception here because the metadata collection is already deleted.
}

View file

@ -340,7 +340,7 @@ class Hamster extends Action
if (!$res) {
Console::error('Failed to create event for project: ' . $project->getId());
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
Console::error('Failed to send stats for project: ' . $project->getId());
Console::error($e->getMessage());
} finally {
@ -410,7 +410,7 @@ class Hamster extends Action
if (!$res) {
throw new \Exception('Failed to create event for organization : ' . $organization->getId());
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
Console::error($e->getMessage());
}
}
@ -464,7 +464,7 @@ class Hamster extends Action
if (!$res) {
throw new \Exception('Failed to create user profile for user: ' . $user->getId());
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
Console::error($e->getMessage());
}
}

View file

@ -130,7 +130,7 @@ class Mails extends Action
try {
$mail->send();
} catch (\Exception $error) {
} catch (\Throwable $error) {
throw new Exception('Error sending mail: ' . $error->getMessage(), 500);
}
}

View file

@ -263,7 +263,7 @@ class Messaging extends Action
}
}
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
$deliveryErrors[] = 'Failed sending to targets ' . $batchIndex + 1 . '-' . \count($batch) . ' with error: ' . $e->getMessage();
} finally {
$batchIndex++;
@ -390,7 +390,7 @@ class Messaging extends Action
->setProject($project)
->addMetric(METRIC_MESSAGES, 1)
->trigger();
} catch (\Exception $e) {
} catch (\Throwable $e) {
throw new Exception('Failed sending to targets ' . $batchIndex + 1 . '-' . \count($batch) . ' with error: ' . $e->getMessage(), 500);
}
};

View file

@ -218,7 +218,7 @@ class Usage extends Action
default:
break;
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
console::error("[reducer] " . " {DateTime::now()} " . " {$project->getInternalId()} " . " {$e->getMessage()}");
}
}

View file

@ -94,7 +94,7 @@ class UsageHook extends Usage
}
}
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
console::error(DateTime::now() . ' ' . $projectInternalId . ' ' . $e->getMessage());
}
}