aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar √Čtienne Deparis 2020-03-22 14:25:09 +0100
committerGravatar √Čtienne Deparis 2020-03-22 14:25:09 +0100
commit830e81fd59205ddfa6835d809bfe35df6014aef4 (patch)
treefe83e6020e0a667501fa721b544842ef6257267b
parent82ed0fdeb3bbbdb5a5004538f633ad3eef8c484d (diff)
downloadneruda-830e81fd59205ddfa6835d809bfe35df6014aef4.zip
neruda-830e81fd59205ddfa6835d809bfe35df6014aef4.tar.gz
neruda-830e81fd59205ddfa6835d809bfe35df6014aef4.tar.xz
Fix error handling in Emacs publish threads
-rw-r--r--lib/neruda/org_file/htmlizer.rb4
-rw-r--r--lib/neruda/utils.rb40
-rw-r--r--lib/tasks/site.rake18
3 files changed, 47 insertions, 15 deletions
diff --git a/lib/neruda/org_file/htmlizer.rb b/lib/neruda/org_file/htmlizer.rb
index 8bce48b..7af1c60 100644
--- a/lib/neruda/org_file/htmlizer.rb
+++ b/lib/neruda/org_file/htmlizer.rb
@@ -70,9 +70,9 @@ module Neruda
command = emacs_command arguments
if @options[:verbose]
warn command
- return system(command)
+ return system(command, exception: true)
end
- system command, out: '/dev/null', err: '/dev/null'
+ system command, out: '/dev/null', err: '/dev/null', exception: true
end
end
end
diff --git a/lib/neruda/utils.rb b/lib/neruda/utils.rb
index b68bfd5..ffa74f3 100644
--- a/lib/neruda/utils.rb
+++ b/lib/neruda/utils.rb
@@ -71,17 +71,19 @@ module Neruda
# @param message [String] the message to display before the throbber
# @return [void]
def throbber(thread, message)
- model = Neruda::Config.settings['throbber'] || 'default'
- model = 'default' unless Neruda::Utils::THROBBER_FRAMES.has_key?(model)
- frames = Neruda::Utils::THROBBER_FRAMES[model]
- current = 0
- while thread.alive?
- sleep 0.1
- print "#{message} #{frames[current % frames.length]}\r"
- current += 1
+ frames = select_throbber_frames
+ begin
+ run_and_decorate_thread thread, message, frames
+ rescue RuntimeError => e
+ done = Rainbow('An error occured.').bold.red + "\n"
+ done += Rainbow('To see it, run again your command with more ' \
+ 'verbosity, i.e. pablo build -v').bold
+ warn "#{message} #{done}"
+ raise e
+ else
+ done = Rainbow('done'.ljust(frames[0].length)).green
+ puts "#{message} #{done}"
end
- done = Rainbow('done'.ljust(frames[0].length)).green
- puts "#{message} #{done}"
end
# Returns the short and long options specification for a given
@@ -153,6 +155,24 @@ module Neruda
return 'apple' if RUBY_PLATFORM =~ /darwin/
'linux'
end
+
+ private
+
+ def select_throbber_frames
+ model = Neruda::Config.settings['throbber'] || 'default'
+ model = 'default' unless Neruda::Utils::THROBBER_FRAMES.has_key?(model)
+ Neruda::Utils::THROBBER_FRAMES[model]
+ end
+
+ def run_and_decorate_thread(thread, message, frames)
+ thread.abort_on_exception = true
+ current = 0
+ while thread.alive?
+ sleep 0.1
+ print "#{message} #{frames[current % frames.length]}\r"
+ current += 1
+ end
+ end
end
end
end
diff --git a/lib/tasks/site.rake b/lib/tasks/site.rake
index f77c27f..610f41b 100644
--- a/lib/tasks/site.rake
+++ b/lib/tasks/site.rake
@@ -28,7 +28,12 @@ namespace :site do
build_html = Thread.new do
Neruda::OrgFile.new(nil, verbose: Rake::FileUtilsExt.verbose_flag).publish
end
- Neruda::Utils.throbber(build_html, 'Publishing:')
+ begin
+ Neruda::Utils.throbber(build_html, 'Publishing:')
+ rescue RuntimeError
+ warn 'Aborting'
+ next
+ end
customize_html = Thread.new do
pubfolder = Neruda::Config.settings['public_folder']
Dir["#{pubfolder}/**/*.html"].each do |f|
@@ -46,8 +51,15 @@ namespace :site do
next
end
verbose = Rake::FileUtilsExt.verbose_flag
- o = Neruda::OrgFile.new(args[:source], verbose: verbose)
- o.publish
+ o = Thread.new do
+ Neruda::OrgFile.new(args[:source], verbose: verbose).publish
+ end
+ begin
+ Neruda::Utils.throbber(o, 'Publishing:')
+ rescue RuntimeError
+ warn 'Aborting'
+ next
+ end
target = Neruda::OrgFile.target_for_source(args[:source])
warn "Customizing file #{target}" if verbose
Neruda::Templater.customize_output(target, o)