Skip to content

Commit

Permalink
Raise on fatal errors instead of exit
Browse files Browse the repository at this point in the history
So that the errors can be caught in specs.
In lavinmq.cr is the exit done
  • Loading branch information
viktorerlingsson committed Dec 18, 2024
1 parent fdbb58e commit 4911532
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/lavinmq.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ config.parse # both ARGV and config file
require "./lavinmq/launcher"
require "./lavinmq/clustering/controller"

if config.clustering?
LavinMQ::Clustering::Controller.new(config).run
else
LavinMQ::Launcher.new(config).run
begin
if config.clustering?
LavinMQ::Clustering::Controller.new(config).run
else
LavinMQ::Launcher.new(config).run
end
rescue LavinMQ::Etcd::NoEtcdEndpoint
exit 5 # 5th character in the alphabet is E(etcd)
end
4 changes: 3 additions & 1 deletion src/lavinmq/etcd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ module LavinMQ
end
end

class NoEtcdEndpoint < Exception; end

private def connect : Tuple(TCPSocket, String)
@endpoints.shuffle!.each do |address|
host, port = address.split(':', 2)
Expand All @@ -276,7 +278,7 @@ module LavinMQ
next
end
Log.fatal { "No etcd endpoint responded" }
exit 5 # 5th character in the alphabet is E(etcd)
raise NoEtcdEndpoint.new
end

private def update_endpoints(tcp, address)
Expand Down

0 comments on commit 4911532

Please sign in to comment.