Trigger the Rescue hook from RequireMigration hook
This commit is contained in:
parent
01183ad228
commit
b191bac700
2 changed files with 9 additions and 6 deletions
|
@ -2,11 +2,12 @@
|
||||||
|
|
||||||
module Twenty::Command::Hook
|
module Twenty::Command::Hook
|
||||||
module RequireMigration
|
module RequireMigration
|
||||||
|
Error = Class.new(RuntimeError)
|
||||||
|
|
||||||
def run_command(...)
|
def run_command(...)
|
||||||
if pending_migrations?
|
if pending_migrations?
|
||||||
warn "There are pending migrations.\n" \
|
raise Error, "There are pending database migrations to run. \n" \
|
||||||
"Run \"twenty migrate\" first.\n"
|
"Try 'twenty migrate'"
|
||||||
exit(1)
|
|
||||||
else
|
else
|
||||||
super(...)
|
super(...)
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
module Twenty::Command::Hook
|
module Twenty::Command::Hook
|
||||||
module Rescue
|
module Rescue
|
||||||
FRAME_MAX = 15
|
FRAME_MAX = 15
|
||||||
|
INDENT_BY = 2
|
||||||
|
|
||||||
def run(...)
|
def run(...)
|
||||||
super(...)
|
super(...)
|
||||||
|
@ -11,7 +12,8 @@ module Twenty::Command::Hook
|
||||||
$stderr.print "\n",
|
$stderr.print "\n",
|
||||||
" ", Paint[" Exception ", :white, :red, :bold], "\n",
|
" ", Paint[" Exception ", :white, :red, :bold], "\n",
|
||||||
" ", Paint[ex.class.to_s, :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",
|
" ", Paint[" Backtrace ", :white, :blue, :bold], "\n",
|
||||||
format_backtrace(ex.backtrace), "\n",
|
format_backtrace(ex.backtrace), "\n",
|
||||||
"\n"
|
"\n"
|
||||||
|
@ -20,8 +22,8 @@ module Twenty::Command::Hook
|
||||||
private
|
private
|
||||||
|
|
||||||
def format_backtrace(backtrace)
|
def format_backtrace(backtrace)
|
||||||
backtrace.last(FRAME_MAX).map do
|
backtrace[0..FRAME_MAX-1].map do
|
||||||
" #{_1.gsub(Dir.getwd, "")}"
|
[" " * INDENT_BY, _1.gsub(Dir.getwd, "")].join
|
||||||
end.join("\n")
|
end.join("\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue