From 44edf3aa915653093718a1df802047153b949dc2 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 23 Oct 2023 14:28:32 +0200 Subject: [PATCH] Improve error handling in mastodon:setup task (#21464) --- lib/tasks/mastodon.rake | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake index f68d1cf1f8..ebf1208380 100644 --- a/lib/tasks/mastodon.rake +++ b/lib/tasks/mastodon.rake @@ -17,6 +17,8 @@ namespace :mastodon do ENV.delete('SIDEKIQ_REDIS_URL') begin + errors = false + prompt.say('Your instance is identified by its domain name. Changing it afterward will break things.') env['LOCAL_DOMAIN'] = prompt.ask('Domain name:') do |q| q.required true @@ -95,7 +97,11 @@ namespace :mastodon do rescue => e prompt.error 'Database connection could not be established with this configuration, try again.' prompt.error e.message - break unless prompt.yes?('Try again?') + unless prompt.yes?('Try again?') + return prompt.warn 'Nothing saved. Bye!' unless prompt.yes?('Continue anyway?') + errors = true + break + end end end @@ -135,7 +141,11 @@ namespace :mastodon do rescue => e prompt.error 'Redis connection could not be established with this configuration, try again.' prompt.error e.message - break unless prompt.yes?('Try again?') + unless prompt.yes?('Try again?') + return prompt.warn 'Nothing saved. Bye!' unless prompt.yes?('Continue anyway?') + errors = true + break + end end end @@ -420,7 +430,11 @@ namespace :mastodon do rescue => e prompt.error 'E-mail could not be sent with this configuration, try again.' prompt.error e.message - break unless prompt.yes?('Try again?') + unless prompt.yes?('Try again?') + return prompt.warn 'Nothing saved. Bye!' unless prompt.yes?('Continue anyway?') + errors = true + break + end end end @@ -466,6 +480,7 @@ namespace :mastodon do prompt.ok 'Done!' else prompt.error 'That failed! Perhaps your configuration is not right' + errors = true end end @@ -482,12 +497,17 @@ namespace :mastodon do prompt.say 'Done!' else prompt.error 'That failed! Maybe you need swap space?' + errors = true end end end prompt.say "\n" - prompt.ok 'All done! You can now power on the Mastodon server 🐘' + if errors + prompt.warn 'Your Mastodon server is set up, but there were some errors along the way, you may have to fix them.' + else + prompt.ok 'All done! You can now power on the Mastodon server 🐘' + end prompt.say "\n" if db_connection_works && prompt.yes?('Do you want to create an admin user straight away?')