Skip to content

Commit

Permalink
Silence metadata loading errors
Browse files Browse the repository at this point in the history
  • Loading branch information
TojikCZ authored and ondratu committed Apr 3, 2024
1 parent 5562b40 commit 871e511
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
ChangeLog
=========
dev
* Silenced errors while parsing metadata from cache and print files

0.2.0alpha1
* Improve automatic thumbnail and preview selection
* `sl1s` added as sla extension gcode type
Expand Down
21 changes: 15 additions & 6 deletions gcode_metadata/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,22 @@ def load(self, save_cache=True):
"""Extract and set metadata from `self.path`. Any metadata
obtained from the path will be overwritten by metadata from
the file if the metadata is contained there as well"""
cache_loaded = False
if self.is_cache_fresh():
self.load_cache()
else:
self.load_from_path(self.path)
self.load_from_file(self.path)
if save_cache:
self.save_cache()
try:
self.load_cache()
cache_loaded = True
except Exception: # pylint: disable=broad-except
log.warning("Failed loading cache for: %s", self.path)
if not cache_loaded:
try:
self.load_from_path(self.path)
self.load_from_file(self.path)
except Exception: # pylint: disable=broad-except
log.exception("Failed loading metadata from: %s", self.path)
else:
if save_cache:
self.save_cache()

def load_from_file(self, path: str):
"""Load metadata and thumbnails from given `path`"""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def give_cache_version(path, version_to_give):
def test_get_metadata_file_does_not_exist():
"""Test get_metadata() with a non-existing file"""
fname = '/somehwere/in/the/rainbow/my.gcode'
with pytest.raises(FileNotFoundError):
get_metadata(fname)
metadata = get_metadata(fname)
assert not metadata.data


def test_save_cache_empty_file():
Expand Down

0 comments on commit 871e511

Please sign in to comment.