better error message on unreadable database

This commit is contained in:
Adrian Sampson 2011-06-02 10:17:53 -07:00
parent b3e1535067
commit 973fca1d89
3 changed files with 19 additions and 4 deletions

1
NEWS
View file

@ -34,6 +34,7 @@
* Fix a rare deadlock when finishing the import pipeline.
* Fix an issue that was causing mpdupdate to run twice for every album.
* Fix a bug that caused release dates/years not to be fetched.
* A better error message is given when the database file is unopenable.
1.0b8
-----

View file

@ -24,6 +24,7 @@ import ConfigParser
import sys
from difflib import SequenceMatcher
import logging
import sqlite3
from beets import library
from beets import plugins
@ -584,10 +585,14 @@ def main(args=None, configfh=None):
path_formats.update(config.items('paths'))
art_filename = \
config_val(config, 'beets', 'art_filename', DEFAULT_ART_FILENAME)
lib = library.Library(os.path.expanduser(libpath),
directory,
path_formats,
art_filename)
db_path = os.path.expanduser(libpath)
try:
lib = library.Library(db_path,
directory,
path_formats,
art_filename)
except sqlite3.OperationalError:
raise UserError("database file %s could not be opened" % db_path)
# Configure the logger.
log = logging.getLogger('beets')

View file

@ -243,6 +243,15 @@ class ConfigTest(unittest.TestCase):
os.environ['BEETSCONFIG'] = '/xxxxx'
ui.main(['version'])
def test_nonexistant_db(self):
def func(lib, config, opts, args):
pass
with self.assertRaises(ui.UserError):
self._run_main([], textwrap.dedent("""
[beets]
library: /xxx/yyy/not/a/real/path
"""), func)
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)