diff --git a/rho/facthashcommand.py b/rho/facthashcommand.py index 7f7471e..b87cbcc 100644 --- a/rho/facthashcommand.py +++ b/rho/facthashcommand.py @@ -101,23 +101,29 @@ def read_and_hash(self, path): keys = None with open(path, 'r') as read_file: - reader = csv.DictReader(read_file, delimiter=',') - for row in reader: - for fact in self.facts_to_hash: - if fact in row: - row[fact] = compute_sha256_hash(row[fact]) - facts_hashed.add(fact) - else: - facts_not_found.add(fact) - if keys is None: - keys = set(row.keys()) - data.append(row) - - for fact in facts_hashed: - print(_("Fact %s hashed" % fact)) - for fact in facts_not_found: - print(_("Fact %s was not present in %s" % - (fact, self.options.report_path))) + try: + reader = csv.DictReader(read_file, delimiter=',') + for row in reader: + for fact in self.facts_to_hash: + if fact in row: + row[fact] = compute_sha256_hash(row[fact]) + facts_hashed.add(fact) + else: + facts_not_found.add(fact) + if keys is None: + keys = set(row.keys()) + data.append(row) + + for fact in facts_hashed: + print(_("Fact %s hashed" % fact)) + for fact in facts_not_found: + print(_("Fact %s was not present in %s" % + (fact, self.options.report_path))) + except csv.Error as csv_error: + print(_("An error occurred while attempting" + " to read CSV file %s." % (self.options.report_path))) + print(csv_error.message) + sys.exit(1) return keys, data