Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: raise the more specific FileNotFoundError #802

Merged
merged 3 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
mattculler marked this conversation as resolved.
Show resolved Hide resolved
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
Loading