Skip to content

Commit

Permalink
fix: raise the more specific FileNotFoundError (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattculler authored Aug 8, 2024
1 parent bed14a4 commit 988ebec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions craft_parts/xattrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def read_xattr(path: str, key: str) -> str | None:

try:
value = os.getxattr(path, key)
except FileNotFoundError:
raise
except OSError as error:
# No label present with:
# OSError: [Errno 61] No data available: b'<path>'
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_xattrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def test_read_xattr(self, test_file):
xattrs.read_xattr(test_file, "attr")
assert str(raised.value) == "xattr support only available for Linux"

def test_read_xattr_nonexistent(self):
with pytest.raises(FileNotFoundError):
xattrs.read_xattr("I-DONT-EXIST", "attr")

def test_write_xattr(self, test_file):
value = "foo"
if sys.platform == "linux":
Expand Down

0 comments on commit 988ebec

Please sign in to comment.