From 53c08488fc1da4fb9183403da313292a64984678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=A1=A5=E1=A0=A0=E1=A1=B3=E1=A1=A4=E1=A1=B3=E1=A0=B6?= =?UTF-8?q?=E1=A0=A0=20=E1=A1=A5=E1=A0=A0=E1=A0=AF=E1=A0=A0=C2=B7=E1=A0=A8?= =?UTF-8?q?=E1=A1=9D=E1=A1=B4=E1=A0=A3=20=E7=8C=AB?= Date: Sun, 7 Jul 2024 04:26:59 +0800 Subject: [PATCH] fix: catch `OSError` when string is too long `OSError: [Errno 36] File name too long` --- biliarchiver/cli_tools/utils.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/biliarchiver/cli_tools/utils.py b/biliarchiver/cli_tools/utils.py index 4f6586c..8613160 100644 --- a/biliarchiver/cli_tools/utils.py +++ b/biliarchiver/cli_tools/utils.py @@ -8,10 +8,13 @@ def read_bvids(bvids: str) -> list[str]: bvids_list = None file = Path(bvids) - if file.exists() and file.is_file(): - with open(file, "r", encoding="utf-8") as f: - bvids_list = f.read().split() - else: + try: + if file.exists() and file.is_file(): + with open(file, "r", encoding="utf-8") as f: + bvids_list = f.read().split() + else: + raise Exception("Not a file") + except Exception as _: bvids_list = bvids.split() del bvids @@ -26,4 +29,4 @@ def read_bvids(bvids: str) -> list[str]: def read_bvids_from_txt(txt_path: Union[Path,str]) -> List[str]: with open(txt_path, "r", encoding="utf-8") as f: bvids = [line.strip() for line in f if line.strip().startswith("BV")] - return bvids \ No newline at end of file + return bvids