lib/spoom/cli/bump.rb in spoom-1.1.15 vs lib/spoom/cli/bump.rb in spoom-1.1.16

- old
+ new

@@ -11,24 +11,40 @@ include Helper default_task :bump desc "bump DIRECTORY", "Change Sorbet sigils from one strictness to another when no errors" - option :from, type: :string, default: Spoom::Sorbet::Sigils::STRICTNESS_FALSE, + option :from, + type: :string, + default: Spoom::Sorbet::Sigils::STRICTNESS_FALSE, desc: "Change only files from this strictness" - option :to, type: :string, default: Spoom::Sorbet::Sigils::STRICTNESS_TRUE, + option :to, + type: :string, + default: Spoom::Sorbet::Sigils::STRICTNESS_TRUE, desc: "Change files to this strictness" - option :force, type: :boolean, default: false, aliases: :f, + option :force, + type: :boolean, + default: false, + aliases: :f, desc: "Change strictness without type checking" option :sorbet, type: :string, desc: "Path to custom Sorbet bin" - option :dry, type: :boolean, default: false, aliases: :d, + option :dry, + type: :boolean, + default: false, + aliases: :d, desc: "Only display what would happen, do not actually change sigils" - option :only, type: :string, default: nil, aliases: :o, + option :only, + type: :string, + default: nil, + aliases: :o, desc: "Only change specified list (one file by line)" - option :suggest_bump_command, type: :string, + option :suggest_bump_command, + type: :string, desc: "Command to suggest if files can be bumped" - option :count_errors, type: :boolean, default: false, + option :count_errors, + type: :boolean, + default: false, desc: "Count the number of errors if all files were bumped" option :sorbet_options, type: :string, default: "", desc: "Pass options to Sorbet" sig { params(directory: String).void } def bump(directory = ".") in_sorbet_project! @@ -83,23 +99,36 @@ undo_changes(files_to_bump, from) if dry exit(files_to_bump.empty?) end error_url_base = Spoom::Sorbet::Errors::DEFAULT_ERROR_URL_BASE - result = Sorbet.srb_tc( - *options[:sorbet_options].split(" "), - "--error-url-base=#{error_url_base}", - path: exec_path, - capture_err: true, - sorbet_bin: options[:sorbet], - ) - - check_sorbet_segfault(result.exit_code) do + result = begin + Sorbet.srb_tc( + *options[:sorbet_options].split(" "), + "--error-url-base=#{error_url_base}", + path: exec_path, + capture_err: true, + sorbet_bin: options[:sorbet], + ) + rescue Spoom::Sorbet::Error::Segfault => error say_error(<<~ERR, status: nil) + !!! Sorbet exited with code #{Spoom::Sorbet::SEGFAULT_CODE} - SEGFAULT !!! + + This is most likely related to a bug in Sorbet. It means one of the file bumped to `typed: #{to}` made Sorbet crash. Run `spoom bump -f` locally followed by `bundle exec srb tc` to investigate the problem. ERR undo_changes(files_to_bump, from) + exit(error.result.exit_code) + rescue Spoom::Sorbet::Error::Killed => error + say_error(<<~ERR, status: nil) + !!! Sorbet exited with code #{Spoom::Sorbet::KILLED_CODE} - KILLED !!! + + It means Sorbet was killed while executing. Changes to files have not been applied. + Re-run `spoom bump` to try again. + ERR + undo_changes(files_to_bump, from) + exit(error.result.exit_code) end if result.status print_changes(files_to_bump, command: cmd, from: from, to: to, dry: dry, path: exec_path) undo_changes(files_to_bump, from) if dry