Class: FuzzBert::Handler::FileOutput

Inherits:
Object
  • Object
show all
Includes:
ConsoleHelper
Defined in:
lib/fuzzbert/error_handler.rb

Instance Method Summary collapse

Methods included from ConsoleHelper

#info

Constructor Details

#initialize(dir = nil) ⇒ FileOutput

Returns a new instance of FileOutput.



21
22
23
24
25
26
# File 'lib/fuzzbert/error_handler.rb', line 21

def initialize(dir=nil)
  @dir = dir
  if @dir && !@dir.end_with?("/")
    @dir << "/"
  end
end

Instance Method Details

#handle(error_data) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fuzzbert/error_handler.rb', line 28

def handle(error_data)
  id = error_data[:id]
  data = error_data[:data]
  status = error_data[:status]
  pid = error_data[:pid]

  crashed = status.termsig
  prefix = crashed ? "crash" : "bug"

  filename = "#{dir_prefix}#{prefix}#{pid}"
  while File.exists?(filename)
    filename << ('a'..'z').to_a.sample
  end
  File.open(filename, "wb") { |f| f.print(data) }

  puts "#{id} failed. Data was saved as #{filename}."
  info(error_data)
end