From c0cfbcee852c452e91e079f8f3be387918b3b919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Sun, 17 Apr 2022 21:53:32 +0200 Subject: [PATCH] fix: Don't crash when trying to compute a download's name Issue #68: https://github.com/pawamoy/aria2p/issues/68 --- src/aria2p/downloads.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/aria2p/downloads.py b/src/aria2p/downloads.py index 0d9c653..0ff2d7c 100644 --- a/src/aria2p/downloads.py +++ b/src/aria2p/downloads.py @@ -5,6 +5,7 @@ torrent files, files and downloads in aria2c. """ +from contextlib import suppress from datetime import datetime, timedelta from pathlib import Path from typing import List, Optional @@ -293,12 +294,11 @@ def name(self) -> str: # noqa: WPS231 dir_path = str(self.dir.absolute()) if file_path.startswith(dir_path): start_pos = len(dir_path) + 1 - self._name = Path(file_path[start_pos:]).parts[0] + with suppress(IndexError): + self._name = Path(file_path[start_pos:]).parts[0] else: - try: + with suppress(IndexError): self._name = self.files[0].uris[0]["uri"].split("/")[-1] # noqa: WPS219 - except IndexError: - pass # noqa: WPS420 (we don't want to fail here) return self._name @property