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}"
|
||||
end
|
||||
|
||||
def failure(msg)
|
||||
puts "ERR #{String(msg).lines.join(' ')}"
|
||||
def failure(data = nil)
|
||||
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
|
||||
|
||||
workdir = ARGV.first
|
||||
|
@ -24,7 +33,6 @@ workdir = File.expand_path(workdir).freeze
|
|||
|
||||
config = Referator::Config.new workdir
|
||||
footnotes = Referator::Footnotes.new config
|
||||
stacktrace = nil
|
||||
|
||||
while (line = $stdin.gets)
|
||||
begin
|
||||
|
@ -38,9 +46,6 @@ while (line = $stdin.gets)
|
|||
exit
|
||||
when :ping
|
||||
success :pong
|
||||
when :stacktrace
|
||||
success stacktrace
|
||||
stacktrace = nil
|
||||
##########
|
||||
# Config #
|
||||
##########
|
||||
|
@ -91,7 +96,6 @@ while (line = $stdin.gets)
|
|||
raise 'Invalid command'
|
||||
end
|
||||
rescue => e
|
||||
stacktrace = e.backtrace.map(&:freeze).freeze
|
||||
failure e.detailed_message
|
||||
failure serialize_err e
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue