Skip to content

Commit

Permalink
Add some more useful error messages in the common situations (file do…
Browse files Browse the repository at this point in the history
…esn't exist, isn't a sqlite db)
  • Loading branch information
jdallien committed Feb 23, 2012
1 parent 7e9e160 commit 58775f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 14 additions & 4 deletions bin/cookie_extractor
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "cookie_

# TODO: Locate cookie dbs automatically
filename = ARGV.first
if filename
extractor = CookieExtractor::BrowserDetector.new_extractor(filename)
puts extractor.extract.join("\n")
else
unless filename
puts "Usage: cookie_extractor /path/to/cookies.sqlite"
exit
end

if File.exists?(filename)
begin
extractor = CookieExtractor::BrowserDetector.new_extractor(filename)
puts extractor.extract.join("\n")
rescue SQLite3::NotADatabaseException,
CookieExtractor::BrowserNotDetectedException
puts "Error: File '#{filename}' is not a Firefox or Chrome cookie database"
end
else
puts "Error: File '#{filename}' does not exist"
end
2 changes: 2 additions & 0 deletions lib/cookie_extractor/browser_detector.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module CookieExtractor
class BrowserNotDetectedException < Exception; end

class BrowserDetector

def self.new_extractor(db_filename)
Expand Down

0 comments on commit 58775f8

Please sign in to comment.