diff --git a/NEWS b/NEWS index ecb2af02d..71da51b3e 100644 --- a/NEWS +++ b/NEWS @@ -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 ----- diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index 188ba98cd..1f5b04c46 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -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') diff --git a/test/test_ui.py b/test/test_ui.py index 5489519f8..fa61da0cb 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -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__)