From 8cd9d53fb1ff4a8a15d208f587a0a4ce330890bd Mon Sep 17 00:00:00 2001 From: Fijxu Date: Thu, 12 Jun 2025 18:44:01 -0400 Subject: [PATCH 1/3] show message when connection to the database is not possible --- src/invidious.cr | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/invidious.cr b/src/invidious.cr index 69f8a26c..d1f84f39 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -60,7 +60,13 @@ alias IV = Invidious CONFIG = Config.load HMAC_KEY = CONFIG.hmac_key -PG_DB = DB.open CONFIG.database_url +PG_DB = begin + DB.open CONFIG.database_url +rescue ex + puts "Failed to connect to PostgreSQL database: #{ex.cause.try &.message}" + puts "Check your 'config.yml' database settings or PostgreSQL settings." + exit(1) +end ARCHIVE_URL = URI.parse("https://archive.org") PUBSUB_URL = URI.parse("https://pubsubhubbub.appspot.com") REDDIT_URL = URI.parse("https://www.reddit.com") From 8723fdca06510a2ab64c194fa284f011fd327e42 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Sat, 21 Jun 2025 12:02:32 -0400 Subject: [PATCH 2/3] Update src/invidious.cr Co-authored-by: Samantaz Fox --- src/invidious.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index d1f84f39..2d244dd2 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -62,8 +62,8 @@ HMAC_KEY = CONFIG.hmac_key PG_DB = begin DB.open CONFIG.database_url -rescue ex - puts "Failed to connect to PostgreSQL database: #{ex.cause.try &.message}" +rescue exc + puts "Failed to connect to PostgreSQL database: #{exc.cause.try &.message}" puts "Check your 'config.yml' database settings or PostgreSQL settings." exit(1) end From 67f93e55d8e9be4c81a58920c4651d2eb1327fd6 Mon Sep 17 00:00:00 2001 From: syeopite Date: Sat, 23 Aug 2025 03:35:59 -0700 Subject: [PATCH 3/3] Fix "ex" variable collision in invidious.cr The exception handling for database connections results in an `ex` variable which Ameba sees as overshadowing the `ex` used by the `ex` block arg used to define the HTTP status code 500 handler below. Although this is a non-issue since the db connection exception handling will cause Invidious to exit, Ameba's nature as a static checker means that it isn't aware of this. The simplest fix without a dirty ameba ignore comment is to rename `ex` within the Kemal handler block below, since `ex` within a begin rescue block is a Crystal convention that will also cause Ameba to raise when not adhered to. --- src/invidious.cr | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 2d244dd2..197b150c 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -62,8 +62,8 @@ HMAC_KEY = CONFIG.hmac_key PG_DB = begin DB.open CONFIG.database_url -rescue exc - puts "Failed to connect to PostgreSQL database: #{exc.cause.try &.message}" +rescue ex + puts "Failed to connect to PostgreSQL database: #{ex.cause.try &.message}" puts "Check your 'config.yml' database settings or PostgreSQL settings." exit(1) end @@ -227,8 +227,8 @@ error 404 do |env| Invidious::Routes::ErrorRoutes.error_404(env) end -error 500 do |env, ex| - error_template(500, ex) +error 500 do |env, exception| + error_template(500, exception) end static_headers do |env|