diff --git a/app/cli.php b/app/cli.php index 668b70d8b..559378bc5 100644 --- a/app/cli.php +++ b/app/cli.php @@ -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); diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 49eabcbf5..defd552aa 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -505,7 +505,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 { diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index 1c5d1ae34..ffcfb8f10 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -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'); } diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index c913fcca5..833e2f81e 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -151,7 +151,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; @@ -195,7 +195,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; diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 4f459dd86..d28dcad56 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -679,7 +679,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'); } } diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index 87d3c12c9..13d0f3374 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -610,7 +610,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()); } @@ -822,7 +822,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); } @@ -852,7 +852,7 @@ App::get('/v1/migrations/firebase/projects') 'projectId' => $project['projectId'], ]; } - } catch (\Exception $e) { + } catch (\Throwable $e) { throw new Exception(Exception::USER_IDENTITY_NOT_FOUND); } diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index 3081b3def..4475b98a2 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -89,7 +89,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://.'); } diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 685c230f4..d381e062c 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -1055,7 +1055,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'); } diff --git a/app/http.php b/app/http.php index 0b17ae5b8..a0d1af34a 100644 --- a/app/http.php +++ b/app/http.php @@ -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'); } diff --git a/app/init.php b/app/init.php index 26f9c7c34..037b399f5 100644 --- a/app/init.php +++ b/app/init.php @@ -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.'); } diff --git a/app/worker.php b/app/worker.php index a1454a63f..2080970ac 100644 --- a/app/worker.php +++ b/app/worker.php @@ -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()); } diff --git a/src/Appwrite/Auth/OAuth2/Firebase.php b/src/Appwrite/Auth/OAuth2/Firebase.php index 9c6403808..0e2859e32 100644 --- a/src/Appwrite/Auth/OAuth2/Firebase.php +++ b/src/Appwrite/Auth/OAuth2/Firebase.php @@ -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; } diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index a0529c5ae..1cbe0d181 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -401,7 +401,7 @@ abstract class Migration try { $stmt->execute(); - } catch (\Exception $e) { + } catch (\Throwable $e) { Console::warning($e->getMessage()); } } diff --git a/src/Appwrite/Platform/Tasks/CalcTierStats.php b/src/Appwrite/Platform/Tasks/CalcTierStats.php index 2c904973a..d8f7ad353 100644 --- a/src/Appwrite/Platform/Tasks/CalcTierStats.php +++ b/src/Appwrite/Platform/Tasks/CalcTierStats.php @@ -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}"); } } diff --git a/src/Appwrite/Platform/Tasks/GetMigrationStats.php b/src/Appwrite/Platform/Tasks/GetMigrationStats.php index b76e0428d..ed10ac345 100644 --- a/src/Appwrite/Platform/Tasks/GetMigrationStats.php +++ b/src/Appwrite/Platform/Tasks/GetMigrationStats.php @@ -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}"); } } diff --git a/src/Appwrite/Platform/Tasks/Hamster.php b/src/Appwrite/Platform/Tasks/Hamster.php index 1dca095e9..126ccd07d 100644 --- a/src/Appwrite/Platform/Tasks/Hamster.php +++ b/src/Appwrite/Platform/Tasks/Hamster.php @@ -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()); } }); diff --git a/src/Appwrite/Platform/Tasks/SDKs.php b/src/Appwrite/Platform/Tasks/SDKs.php index 256b36d88..5ecd10f8c 100644 --- a/src/Appwrite/Platform/Tasks/SDKs.php +++ b/src/Appwrite/Platform/Tasks/SDKs.php @@ -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()); } diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index d9ab2ad81..d23cfbff9 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -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; } diff --git a/src/Appwrite/Platform/Workers/Databases.php b/src/Appwrite/Platform/Workers/Databases.php index 0b670cbe5..ae8ed3162 100644 --- a/src/Appwrite/Platform/Workers/Databases.php +++ b/src/Appwrite/Platform/Workers/Databases.php @@ -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()); diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index f22fa9ca4..e227e1a41 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -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. } diff --git a/src/Appwrite/Platform/Workers/Hamster.php b/src/Appwrite/Platform/Workers/Hamster.php index 0fb705d0f..71d7e9012 100644 --- a/src/Appwrite/Platform/Workers/Hamster.php +++ b/src/Appwrite/Platform/Workers/Hamster.php @@ -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()); } } diff --git a/src/Appwrite/Platform/Workers/Mails.php b/src/Appwrite/Platform/Workers/Mails.php index 8cfcf3401..ac9c44c3b 100644 --- a/src/Appwrite/Platform/Workers/Mails.php +++ b/src/Appwrite/Platform/Workers/Mails.php @@ -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); } } diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index 57a0e5f64..149dcad55 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -254,7 +254,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++; @@ -362,7 +362,7 @@ class Messaging extends Action try { $adapter->send($data); - } catch (\Exception $e) { + } catch (\Throwable $e) { Console::error('Failed sending to targets ' . $batchIndex + 1 . '-' . \count($batch) . ' with error: ' . $e->getMessage()); // TODO: Find a way to log into Sentry } }; diff --git a/src/Appwrite/Platform/Workers/Usage.php b/src/Appwrite/Platform/Workers/Usage.php index 5537fae50..7cf6edf51 100644 --- a/src/Appwrite/Platform/Workers/Usage.php +++ b/src/Appwrite/Platform/Workers/Usage.php @@ -231,7 +231,7 @@ class Usage extends Action default: break; } - } catch (\Exception $e) { + } catch (\Throwable $e) { console::error("[reducer] " . " {DateTime::now()} " . " {$project->getInternalId()} " . " {$e->getMessage()}"); } } diff --git a/src/Appwrite/Platform/Workers/UsageHook.php b/src/Appwrite/Platform/Workers/UsageHook.php index 68e6a3fed..2a2286212 100644 --- a/src/Appwrite/Platform/Workers/UsageHook.php +++ b/src/Appwrite/Platform/Workers/UsageHook.php @@ -129,7 +129,7 @@ class UsageHook extends Usage } } } - } catch (\Exception $e) { + } catch (\Throwable $e) { console::error(DateTime::now() . ' ' . $projectInternalId . ' ' . $e->getMessage()); } }