Skip to content

Commit

Permalink
Catch all errors when loading state file.
Browse files Browse the repository at this point in the history
A crash during the multi-threaded import process may leave the pickled
state invalid (see #913). We recover from all these errors.
  • Loading branch information
Thomas Scholtes committed Aug 24, 2014
1 parent 132fad8 commit 225ce62
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion beets/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _open_state():
try:
with open(config['statefile'].as_filename()) as f:
return pickle.load(f)
except (IOError, EOFError):
except:
return {}


Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Changelog

This release adds **sorting** to beets queries. See :ref:`query-sort`.

Fixes:

* Invalid state files don't crash the importer.


1.3.7 (August 22, 2014)
-----------------------
Expand Down
7 changes: 7 additions & 0 deletions test/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,13 @@ def test_incremental_item(self):
importer.run()
self.assertEqual(len(self.lib.items()), 2)

def test_invalid_state_file(self):
importer = self.create_importer()
with open(self.config['statefile'].as_filename(), 'w') as f:
f.write('000')
importer.run()
self.assertEqual(len(self.lib.albums()), 1)


def suite():
return unittest.TestLoader().loadTestsFromName(__name__)
Expand Down

0 comments on commit 225ce62

Please sign in to comment.