{"record":{"id":"7f52a5e57928725b","repo":"harry0703/MoneyPrinterTurbo","slug":"description-path-cannot-be-empty","errorCode":null,"errorMessage":"{description} path cannot be empty","messagePattern":"(.+?) path cannot be empty","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"cli.py","lineNumber":591,"sourceCode":"\n\ndef _resolve_cli_file(\n    raw_path: str,\n    *,\n    description: str,\n    fallback_dir: str | None = None,\n) -> str:\n    \"\"\"\n    将 CLI 文件参数按当前工作目录解析为绝对路径，\n    并在任务开始前确认存在。\n\n    本地素材旧版本始终相对 ``storage/local_videos`` 解析。为兼容已有脚本，\n    当前目录找不到相对路径时允许回退该目录；绝对路径始终按用户输入\n    直接解析。\n    \"\"\"\n    expanded_path = os.path.expanduser(raw_path.strip())\n    if not expanded_path:\n        raise ValueError(f\"{description} path cannot be empty\")\n\n    candidate = (\n        expanded_path\n        if os.path.isabs(expanded_path)\n        else os.path.join(os.getcwd(), expanded_path)\n    )\n    resolved_path = os.path.realpath(candidate)\n    if not os.path.isfile(resolved_path) and fallback_dir and not os.path.isabs(expanded_path):\n        resolved_path = os.path.realpath(os.path.join(fallback_dir, expanded_path))\n\n    if not os.path.isfile(resolved_path):\n        raise ValueError(f\"{description} file does not exist: {raw_path}\")\n    return resolved_path\n\n\ndef _path_is_within_directory(file_path: str, directory: str) -> bool:\n    try:\n        return os.path.commonpath(","sourceCodeStart":573,"sourceCodeEnd":609,"githubUrl":"https://github.com/harry0703/MoneyPrinterTurbo/blob/1f9f19c2021a68d04df228f33e9099a0c947f6f8/cli.py#L573-L609","documentation":"CLI helper that turns a file argument into an absolute, verified path: after strip() and expanduser(), an empty string means the user passed a blank --video-file/--audio-file style argument, and it raises ValueError with the parameter description embedded.","triggerScenarios":"Running the CLI with an argument that expands to nothing: an empty string, a path of only spaces, or a bare '~' that expanduser leaves in a form the check still catches; shell scripts passing an unset variable ('$UNSET_VAR' expanding to '').","commonSituations":"Shell script passes \"$VIDEO_FILE\" when the variable is unset; user quotes an empty string by mistake; config-driven invocation where a field was left blank.","solutions":["Supply an actual file path for the argument.","In scripts, guard: [ -z \"$VIDEO_FILE\" ] && { echo 'VIDEO_FILE required'; exit 1; }.","Use parameter defaults like ${VIDEO_FILE:?VIDEO_FILE required} to fail early with a clear message."],"exampleFix":"# before\npython cli.py --file \"\"\n\n# after\npython cli.py --file ./input/video1.mp4","handlingStrategy":"validation","validationCode":"import os\nif not os.path.expanduser((raw_path or \"\").strip()):\n    raise ValueError(\"file argument must not be empty\")","typeGuard":"def is_nonempty_cli_path(raw: str | None) -> bool:\n    return isinstance(raw, str) and bool(os.path.expanduser(raw.strip()))","tryCatchPattern":null,"preventionTips":["In shell scripts use ${VAR:?message} so unset variables abort before the CLI runs.","Validate required CLI args right after argparse."],"tags":["cli","validation","arguments"],"backgroundTag":null,"analyzedSha":"1f9f19c2021a68d04df228f33e9099a0c947f6f8","analyzedAt":"2026-08-14T19:41:05.568Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}