Skip to content

Commit

Permalink
Improve error handling when aquatone-gather is run on system without X11
Browse files Browse the repository at this point in the history
Nightmarejs will fail to process pages when run on a system without a
graphical desktop session and would make aquatone-gather fail all pages
processings with a rather obscure `JSON::ParserError` exception.

If JSON fails to parse the Nightmarejs driver will raise
`Aquatone::Browser::Drivers::IncompatabilityError` exception which tells
the user to run aquatone in a system with a graphical desktop session.
  • Loading branch information
Michael Henriksen committed Jun 24, 2017
1 parent 7d03f04 commit 3b26121
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Capture potential `NameError` exception in `asked_for_progress?` method,
related to known JRuby bug (issue #4)
- Capture potential `Errno::EBADF` exception in `asked_for_progress?` method (issue #15)
- Improve handling of error when aquatone-gather is run on a system without a graphical desktop session (X11)


## [0.1.1]
Expand Down
5 changes: 5 additions & 0 deletions lib/aquatone/browser/drivers/nightmare.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module Aquatone
class Browser
module Drivers

class IncompatabilityError < StandardError; end

class Nightmare
attr_reader :url, :vhost, :html_destination, :headers_destination, :screenshot_destination, :options

Expand All @@ -23,6 +26,8 @@ def visit
wout.close
command_output = rout.readlines.join("\n").strip
JSON.parse(command_output)
rescue JSON::ParserError
fail IncompatabilityError, "Nightmarejs must be run on a system with a graphical desktop session (X11)"
rescue => e
process.stop if process
return {
Expand Down
26 changes: 16 additions & 10 deletions lib/aquatone/commands/gather.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,23 @@ def process_pages
@tasks.shuffle.each do |task|
host, port, domain = task
pool.schedule do
output_progress if asked_for_progress?
visit = visit_page(host, port, domain)
if visit['success']
output("#{green('Processed:')} #{Aquatone::UrlMaker.make(host, port)} (#{domain}) - #{visit['status']}\n")
@successful += 1
else
output(" #{red('Failed:')} #{Aquatone::UrlMaker.make(host, port)} (#{domain}) - #{visit['error']} #{visit['details']}\n")
@failed += 1
begin
output_progress if asked_for_progress?
visit = visit_page(host, port, domain)
if visit['success']
output("#{green('Processed:')} #{Aquatone::UrlMaker.make(host, port)} (#{domain}) - #{visit['status']}\n")
@successful += 1
else
output(" #{red('Failed:')} #{Aquatone::UrlMaker.make(host, port)} (#{domain}) - #{visit['error']} #{visit['details']}\n")
@failed += 1
end
jitter_sleep
@task_count += 1
rescue Aquatone::Browser::Drivers::IncompatabilityError => e
output("\n")
output(red("Incompatability Error:") + " #{e.message}\n")
exit 1
end
jitter_sleep
@task_count += 1
end
end
pool.shutdown
Expand Down

0 comments on commit 3b26121

Please sign in to comment.