Skip to content

Commit 5f1fb79

Browse files
committed
beetbox#1676 Add a more descriptive error message
A useful error message if we get an OperationalError from SQLite that indicates a permissions problem on write.
1 parent d064f19 commit 5f1fb79

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

beets/dbcore/db.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,17 @@ def mutate(self, statement, subvals=()):
668668
"""Execute an SQL statement with substitution values and return
669669
the row ID of the last affected row.
670670
"""
671-
cursor = self.db._connection().execute(statement, subvals)
672-
return cursor.lastrowid
671+
try:
672+
cursor = self.db._connection().execute(statement, subvals)
673+
return cursor.lastrowid
674+
except sqlite3.OperationalError as exe:
675+
if exe.message == "unable to open database file":
676+
print("ERROR: ", exe)
677+
print(
678+
"Sorry, but there is a problem opening your database file."
679+
" Make sure the directory containing your database file "
680+
"has write permissions.")
681+
raise
673682

674683
def script(self, statements):
675684
"""Execute a string containing multiple SQL statements."""

docs/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Changelog
22
=========
33

4+
* Give some helpful extra info in the event of a
5+
"sqlite3.OperationalError: unable to open database file". :bug:`1676`
6+
47
1.3.17 (in development)
58
-----------------------
69

0 commit comments

Comments
 (0)