From b191bac700c918100c58c1de03f2ff03d8d6b8cf Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sat, 27 Apr 2024 03:21:10 -0300 Subject: [PATCH] Trigger the Rescue hook from RequireMigration hook --- cli/lib/twenty/cli/command/hook/require_migration.rb | 7 ++++--- cli/lib/twenty/cli/command/hook/rescue.rb | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cli/lib/twenty/cli/command/hook/require_migration.rb b/cli/lib/twenty/cli/command/hook/require_migration.rb index 42c3e95..8894cdd 100644 --- a/cli/lib/twenty/cli/command/hook/require_migration.rb +++ b/cli/lib/twenty/cli/command/hook/require_migration.rb @@ -2,11 +2,12 @@ module Twenty::Command::Hook module RequireMigration + Error = Class.new(RuntimeError) + def run_command(...) if pending_migrations? - warn "There are pending migrations.\n" \ - "Run \"twenty migrate\" first.\n" - exit(1) + raise Error, "There are pending database migrations to run. \n" \ + "Try 'twenty migrate'" else super(...) end diff --git a/cli/lib/twenty/cli/command/hook/rescue.rb b/cli/lib/twenty/cli/command/hook/rescue.rb index 1a5a95c..8fd1292 100644 --- a/cli/lib/twenty/cli/command/hook/rescue.rb +++ b/cli/lib/twenty/cli/command/hook/rescue.rb @@ -3,6 +3,7 @@ module Twenty::Command::Hook module Rescue FRAME_MAX = 15 + INDENT_BY = 2 def run(...) super(...) @@ -11,7 +12,8 @@ module Twenty::Command::Hook $stderr.print "\n", " ", Paint[" Exception ", :white, :red, :bold], "\n", " ", Paint[ex.class.to_s, :bold], "\n", - " ", ex.message, "\n\n", + ex.message.each_line.map { [" " * INDENT_BY, _1] }.join, + "\n\n", " ", Paint[" Backtrace ", :white, :blue, :bold], "\n", format_backtrace(ex.backtrace), "\n", "\n" @@ -20,8 +22,8 @@ module Twenty::Command::Hook private def format_backtrace(backtrace) - backtrace.last(FRAME_MAX).map do - " #{_1.gsub(Dir.getwd, "")}" + backtrace[0..FRAME_MAX-1].map do + [" " * INDENT_BY, _1.gsub(Dir.getwd, "")].join end.join("\n") end end