From 743b360d60fe717d4df49da72174ca7d99f09158 Mon Sep 17 00:00:00 2001 From: Brian Carrier <carrier@sleuthkit.org> Date: Wed, 19 Aug 2015 23:47:59 -0400 Subject: [PATCH] Added more specific exception handling to python example --- .../Aug2015DataSourceTutorial/FindContactsDb.py | 14 +++++++------- pythonExamples/Aug2015DataSourceTutorial/RunExe.py | 4 +++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pythonExamples/Aug2015DataSourceTutorial/FindContactsDb.py b/pythonExamples/Aug2015DataSourceTutorial/FindContactsDb.py index a629cb5097..ddaa7eac43 100755 --- a/pythonExamples/Aug2015DataSourceTutorial/FindContactsDb.py +++ b/pythonExamples/Aug2015DataSourceTutorial/FindContactsDb.py @@ -135,16 +135,16 @@ def process(self, dataSource, progressBar): try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % lclDbPath) - except: - self.log(Level.INFO, "Could not open database file (not SQLite) " + file.getName()) + except SQLException as e: + self.log(Level.INFO, "Could not open database file (not SQLite) " + file.getName() + " (" + e.getMessage() + ")") return IngestModule.ProcessResult.OK # Query the contacts table in the database and get all columns. - try: + try: stmt = dbConn.createStatement() resultSet = stmt.executeQuery("SELECT * FROM contacts") - except: - self.log(Level.INFO, "Error querying database for contacts table") + except SQLException as e: + self.log(Level.INFO, "Error querying database for contacts table (" + e.getMessage() + ")") return IngestModule.ProcessResult.OK # Cycle through each row and create artifacts @@ -153,8 +153,8 @@ def process(self, dataSource, progressBar): name = resultSet.getString("name") email = resultSet.getString("email") phone = resultSet.getString("phone") - except: - self.log(Level.INFO, "Error getting values from contacts table") + except SQLException as e: + self.log(Level.INFO, "Error getting values from contacts table (" + e.getMessage() + ")") # Make an artifact on the blackboard, TSK_CONTACT and give it attributes for each of the fields diff --git a/pythonExamples/Aug2015DataSourceTutorial/RunExe.py b/pythonExamples/Aug2015DataSourceTutorial/RunExe.py index 606e73712d..19a6928958 100755 --- a/pythonExamples/Aug2015DataSourceTutorial/RunExe.py +++ b/pythonExamples/Aug2015DataSourceTutorial/RunExe.py @@ -134,6 +134,8 @@ def process(self, dataSource, progressBar): reportHandle = open(reportPath, 'w') # Run the EXE, saving output to the report + # NOTE: we should really be checking for if the module has been + # cancelled and then killing the process. self.log(Level.INFO, "Running program on data source") subprocess.Popen([self.path_to_exe, imagePaths[0]], stdout=reportHandle).communicate()[0] reportHandle.close() @@ -141,4 +143,4 @@ def process(self, dataSource, progressBar): # Add the report to the case, so it shows up in the tree Case.getCurrentCase().addReport(reportPath, "Run EXE", "img_stat output") - return IngestModule.ProcessResult.OK \ No newline at end of file + return IngestModule.ProcessResult.OK -- GitLab