From f3a2bdf5d0a0e60c91711610e5ea4bd01fd51d1c Mon Sep 17 00:00:00 2001 From: Tim Riley Date: Fri, 30 Oct 2026 09:00:20 +1100 Subject: [PATCH] =?UTF-8?q?Use=20Dry=20CLI=E2=80=99s=20native=20exit=20han?= =?UTF-8?q?dling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove our manual catch from `exe/hanami` - Make `Hanami::CLI::Error` inherit from `Dry::CLI::ExitError` --- exe/hanami | 13 +------------ lib/hanami/cli/errors.rb | 7 ++++++- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/exe/hanami b/exe/hanami index b55e2f79..d3f02d9d 100755 --- a/exe/hanami +++ b/exe/hanami @@ -6,15 +6,4 @@ require "hanami/cli" cli = Dry::CLI.new(Hanami::CLI) Hanami::CLI::Bundler.require(:cli) - -code = catch(:exit) { - begin - cli.call - 0 - rescue Hanami::CLI::Error => exception - $stderr.puts(exception.message) # rubocop:disable Style/StderrPuts - 1 - end -} - -exit(code) +cli.call diff --git a/lib/hanami/cli/errors.rb b/lib/hanami/cli/errors.rb index 7dcba27b..46c26485 100644 --- a/lib/hanami/cli/errors.rb +++ b/lib/hanami/cli/errors.rb @@ -2,9 +2,14 @@ module Hanami module CLI + # This is a `Dry::CLI::ExitError`, so the CLI prints its message to stderr and exits with 1. + # # @since 0.1.0 # @api public - class Error < StandardError + class Error < Dry::CLI::ExitError + def initialize(message = self.class.name, exit_code: 1) + super + end end # @since 2.0.0