Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Gracefully handle DatabaseErrors from SQLite

  • Loading branch information...
commit 3cf21cec44b82ae961d2720e67244d479737ad23 1 parent 2243774
polyatail authored
Showing with 7 additions and 6 deletions.
  1. +7 −6 Bio/AlignIO/MafIO.py
13 Bio/AlignIO/MafIO.py
View
@@ -181,6 +181,7 @@ def __init__(self, sqlite_file, maf_file, target_seqname):
from sqlite3 import dbapi2 as _sqlite
from sqlite3 import IntegrityError as _IntegrityError
from sqlite3 import OperationalError as _OperationalError
+ from sqlite3 import DatabaseError as _DatabaseError
except ImportError:
from Bio import MissingPythonDependencyError
raise MissingPythonDependencyError("Requires sqlite3, which is "
@@ -195,11 +196,11 @@ def __init__(self, sqlite_file, maf_file, target_seqname):
raise ValueError("Error opening %s -- file not found" % (maf_file,))
# if sqlite_file exists, use the existing db, otherwise index the file
- if os.path.isfile(sqlite_file):
- con = _sqlite.connect(sqlite_file)
- self._con = con
-
+ if os.path.isfile(sqlite_file):
try:
+ con = _sqlite.connect(sqlite_file)
+ self._con = con
+
idx_version = int(con.execute("SELECT value FROM meta_data WHERE key = 'version'").fetchone()[0])
if idx_version != 1:
@@ -226,8 +227,8 @@ def __init__(self, sqlite_file, maf_file, target_seqname):
raise ValueError("Expected %s records, found %s. Corrupt index?" % (record_count, records_found))
self._record_count = records_found
- except _OperationalError, err:
- raise ValueError("Not a Biopython index database? %s" % err)
+ except (_OperationalError, _DatabaseError), err:
+ raise ValueError("Problem with SQLite database: %s" % err)
else:
con = _sqlite.connect(sqlite_file)
self._con = con
Please sign in to comment.
Something went wrong with that request. Please try again.