From 4f4132f1a11797bf1aecc66ae5735257845953ae Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 15 Mar 2024 10:26:23 -0400 Subject: [PATCH] Add diagnostic message for failure during CLI search deploy (#29462) --- lib/mastodon/cli/search.rb | 8 ++++++++ spec/lib/mastodon/cli/search_spec.rb | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/mastodon/cli/search.rb b/lib/mastodon/cli/search.rb index 5901c07776..3a73c9c047 100644 --- a/lib/mastodon/cli/search.rb +++ b/lib/mastodon/cli/search.rb @@ -100,6 +100,14 @@ module Mastodon::CLI progress.finish say("Indexed #{added} records, de-indexed #{removed}", :green, true) + rescue Elasticsearch::Transport::Transport::ServerError => e + fail_with_message <<~ERROR + There was an issue connecting to the search server. Make sure the + server is configured and running correctly, and that the environment + variable settings match what the server is expecting. + + #{e.message} + ERROR end private diff --git a/spec/lib/mastodon/cli/search_spec.rb b/spec/lib/mastodon/cli/search_spec.rb index 8cce2c6ee2..ed3789c3e7 100644 --- a/spec/lib/mastodon/cli/search_spec.rb +++ b/spec/lib/mastodon/cli/search_spec.rb @@ -33,6 +33,17 @@ describe Mastodon::CLI::Search do end end + context 'when server communication raises an error' do + let(:options) { { reset_chewy: true } } + + before { allow(Chewy::Stash::Specification).to receive(:reset!).and_raise(Elasticsearch::Transport::Transport::Errors::InternalServerError) } + + it 'Exits with error message' do + expect { subject } + .to raise_error(Thor::Error, /issue connecting to the search/) + end + end + context 'without options' do before { stub_search_indexes }