Skip to content

Commit 3c082fa

Browse files
committed
Improve arg parse error messages
1 parent 95ec40c commit 3c082fa

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

auto_editor/ffwrapper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def initFileInfo(path: str, log: Log) -> FileInfo:
195195
try:
196196
cont = av.open(path, "r")
197197
except av.error.FileNotFoundError:
198-
log.error(f"Could not find '{path}'")
198+
log.error(f"Input file doesn't exist: {path}")
199199
except av.error.IsADirectoryError:
200200
log.error(f"Expected a media file, but got a directory: {path}")
201201
except av.error.InvalidDataError:

auto_editor/subcommands/test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def input_extension():
309309
"""Input file must have an extension. Throw error if none is given."""
310310

311311
shutil.copy("example.mp4", "example")
312-
run.check(["example", "--no-open"], "must have an extension.")
312+
run.check(["example", "--no-open"], "must have an extension")
313313

314314
return "example"
315315

auto_editor/validate_input.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from __future__ import annotations
22

3-
import os
43
import re
54
import subprocess
65
import sys
6+
from os.path import exists, isdir, isfile, lexists, splitext
77

88
from auto_editor.ffwrapper import FFmpeg
99
from auto_editor.utils.func import get_stdout
@@ -27,7 +27,7 @@ def download_video(my_input: str, args: Args, ffmpeg: FFmpeg, log: Log) -> str:
2727
download_format = "bestvideo[ext=mp4]+bestaudio[ext=m4a]"
2828

2929
if args.output_format is None:
30-
output_format = re.sub(r"\W+", "-", os.path.splitext(my_input)[0]) + ".%(ext)s"
30+
output_format = re.sub(r"\W+", "-", splitext(my_input)[0]) + ".%(ext)s"
3131
else:
3232
output_format = args.output_format
3333

@@ -57,10 +57,10 @@ def download_video(my_input: str, args: Args, ffmpeg: FFmpeg, log: Log) -> str:
5757
msg += "pip or your favorite package manager and make sure it's in PATH."
5858
log.error(msg)
5959

60-
if not os.path.isfile(location):
60+
if not isfile(location):
6161
subprocess.run([yt_dlp_path] + cmd)
6262

63-
if not os.path.isfile(location):
63+
if not isfile(location):
6464
log.error(f"Download file wasn't created: {location}")
6565

6666
return location
@@ -73,11 +73,16 @@ def valid_input(inputs: list[str], ffmpeg: FFmpeg, args: Args, log: Log) -> list
7373
if my_input.startswith("http://") or my_input.startswith("https://"):
7474
result.append(download_video(my_input, args, ffmpeg, log))
7575
else:
76-
_, ext = os.path.splitext(my_input)
76+
_, ext = splitext(my_input)
7777
if ext == "":
78-
if os.path.isdir(my_input):
78+
if isdir(my_input):
7979
log.error("Input must be a file or a URL, not a directory.")
80-
log.error("Input file must have an extension.")
80+
if exists(my_input):
81+
log.error(f"Input file must have an extension: {my_input}")
82+
if lexists(my_input):
83+
log.error(f"Input file is a broken symbolic link: {my_input}")
84+
if my_input.startswith("-"):
85+
log.error(f"Option/Input file doesn't exist: {my_input}")
8186
result.append(my_input)
8287

8388
return result

0 commit comments

Comments
 (0)