From 7d1b57bc19f274bfee2e653f4c367e8a76d11733 Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Thu, 5 Feb 2026 09:11:47 +0000 Subject: [PATCH] More graceful recovery from errors --- lib/oauth/util.rb | 7 ++++--- lib/tasks/dev.rake | 9 ++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/oauth/util.rb b/lib/oauth/util.rb index b75266270..e5836b060 100644 --- a/lib/oauth/util.rb +++ b/lib/oauth/util.rb @@ -4,6 +4,8 @@ module Oauth module Util OAUTH_SETTINGS_KEYS = [:id_application, :oauth_application, :oauth_key].freeze + class ExistingSettingsError < StandardError; end + def self.register_apps(display_name, generated_by: name, output: $stdout) settings_path = Rails.root.join("config/settings.local.yml") @@ -60,10 +62,9 @@ module Oauth output.puts "- #{key}" end - output.puts "" - output.puts "Delete or comment them out to proceed." + output.puts "Delete or comment them out to regenerate." - raise "App settings already defined" + raise ExistingSettingsError end end end diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index 67446413f..7bc195e82 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -45,6 +45,13 @@ namespace :dev do create_user(:display_name => "mapper", :password => "password", :email => "mapper@example.com") end - Oauth::Util.register_apps("admin") + begin + # Empty line to separate the output of this + # from that of the above + puts + Oauth::Util.register_apps("admin") + rescue Oauth::Util::ExistingSettingsError + # Error here is no big deal + end end end -- 2.39.5