require 'curses'
require 'fileutils'
require 'trollop'
+require 'fastthread'
require "sup"
BIN_VERSION = "git"
exit(-1)
end
-$exceptions = []
$opts = Trollop::options do
version "sup v#{Redwood::VERSION}"
banner <<EOS
SearchResultsMode.spawn_from_query $opts[:search]
end
- until $exceptions.nonempty? || SuicideManager.die?
+ until Redwood::exceptions.nonempty? || SuicideManager.die?
c = Ncurses.nonblocking_getch
next unless c
bm.erase_flash
bm.kill_all_buffers if SuicideManager.die?
rescue Exception => e
- $exceptions << [e, "main"]
+ Redwood::record_exception e, "main"
ensure
unless $opts[:no_threads]
PollManager.stop if PollManager.instantiated?
Redwood::log "I've been ordered to commit seppuku. I obey!"
end
- if $exceptions.empty?
+ if Redwood::exceptions.empty?
Redwood::log "no fatal errors. good job, william."
Index.save
else
Index.unlock
end
-unless $exceptions.empty?
+unless Redwood::exceptions.empty?
File.open(File.join(BASE_DIR, "exception-log.txt"), "w") do |f|
- $exceptions.each do |e, name|
+ Redwood::exceptions.each do |e, name|
f.puts "--- #{e.class.name} from thread: #{name}"
f.puts e.message, e.backtrace
end
William
----------------------------------------------------------------
EOS
- $exceptions.each do |e, name|
+ Redwood::exceptions.each do |e, name|
puts "--- #{e.class.name} from thread: #{name}"
puts e.message, e.backtrace
end
YAML_DOMAIN = "masanjin.net"
YAML_DATE = "2006-10-01"
-## record exceptions thrown in threads nicely
+ ## record exceptions thrown in threads nicely
+ @exceptions = []
+ @exception_mutex = Mutex.new
+
+ attr_reader :exceptions
+ def record_exception e, name
+ @exception_mutex.synchronize do
+ @exceptions ||= []
+ @exceptions << [e, name]
+ end
+ end
+
def reporting_thread name
if $opts[:no_threads]
yield
begin
yield
rescue Exception => e
- $exceptions ||= []
- $exceptions << [e, name]
- raise
+ record_exception e, name
end
end
end
end
- module_function :reporting_thread
+
+ module_function :reporting_thread, :record_exception, :exceptions
## one-stop shop for yamliciousness
def save_yaml_obj object, fn, safe=false