Better serialize errors
This commit is contained in:
parent
82ee397529
commit
454784f61a
1 changed files with 12 additions and 8 deletions
|
@ -14,8 +14,17 @@ def success(data = nil)
|
||||||
puts "OK #{data.to_json}"
|
puts "OK #{data.to_json}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def failure(msg)
|
def failure(data = nil)
|
||||||
puts "ERR #{String(msg).lines.join(' ')}"
|
puts "ERR #{data.to_json}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def serialize_err(err)
|
||||||
|
{
|
||||||
|
class: err.class.name.freeze,
|
||||||
|
message: err.message.freeze,
|
||||||
|
stacktrace: err.backtrace.map(&:freeze).freeze,
|
||||||
|
cause: err.cause.nil? ? nil : serialize_err(err.cause),
|
||||||
|
}.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
workdir = ARGV.first
|
workdir = ARGV.first
|
||||||
|
@ -24,7 +33,6 @@ workdir = File.expand_path(workdir).freeze
|
||||||
|
|
||||||
config = Referator::Config.new workdir
|
config = Referator::Config.new workdir
|
||||||
footnotes = Referator::Footnotes.new config
|
footnotes = Referator::Footnotes.new config
|
||||||
stacktrace = nil
|
|
||||||
|
|
||||||
while (line = $stdin.gets)
|
while (line = $stdin.gets)
|
||||||
begin
|
begin
|
||||||
|
@ -38,9 +46,6 @@ while (line = $stdin.gets)
|
||||||
exit
|
exit
|
||||||
when :ping
|
when :ping
|
||||||
success :pong
|
success :pong
|
||||||
when :stacktrace
|
|
||||||
success stacktrace
|
|
||||||
stacktrace = nil
|
|
||||||
##########
|
##########
|
||||||
# Config #
|
# Config #
|
||||||
##########
|
##########
|
||||||
|
@ -91,7 +96,6 @@ while (line = $stdin.gets)
|
||||||
raise 'Invalid command'
|
raise 'Invalid command'
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
stacktrace = e.backtrace.map(&:freeze).freeze
|
failure serialize_err e
|
||||||
failure e.detailed_message
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue