Skip to content

Commit

Permalink
Improve error message when DuProcessor.from_du_listing fails
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed May 5, 2024
1 parent ad736b8 commit 7e30b21
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions duviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class DuProcessor:
Size tree from `du` (disk usage) listings
"""

_du_regex = re.compile(r'([0-9]*)\s*(.*)')
_du_regex = re.compile(r"([0-9]+)\s*(.+)")

@classmethod
def from_du(
Expand Down Expand Up @@ -157,10 +157,13 @@ def from_du_listing(
) -> SizeTree:
def pairs(lines: Iterable[str]) -> Iterator[Tuple[List[str], int]]:
for line in lines:
kb, path = cls._du_regex.match(line).group(1, 2)
if progress_report:
progress_report(path)
yield path_split(path, root)[1:], 1024 * int(kb)
try:
kb, path = cls._du_regex.match(line).group(1, 2)
if progress_report:
progress_report(path)
yield path_split(path, root)[1:], 1024 * int(kb)
except Exception as e:
raise ValueError(f"Failed to parse {line!r}") from e

return SizeTree.from_path_size_pairs(root=root, pairs=pairs(du_listing))

Expand Down

0 comments on commit 7e30b21

Please sign in to comment.