{"record":{"id":"a7d666ffffa1c063","repo":"harry0703/MoneyPrinterTurbo","slug":"request-id-background-music-validation-is-unava","errorCode":null,"errorMessage":"{request_id}: background music validation is unavailable","messagePattern":"(.+?): background music validation is unavailable","errorType":"http","errorClass":"HttpException","httpStatus":500,"severity":"error","filePath":"app/controllers/v1/video.py","lineNumber":364,"sourceCode":"        safe_filename = bgm_service.save_bgm_upload(file.filename, file.file)\n    except bgm_service.BgmUploadError as exc:\n        # 上传失败通常可以由用户更换文件后恢复，因此记录 request_id 和明确原因，\n        # 但不输出文件内容或绝对路径，避免日志泄露用户数据。\n        logger.warning(\n            f\"background music upload rejected: request_id={request_id}, error={str(exc)}\"\n        )\n        raise HttpException(\n            task_id=request_id,\n            status_code=400,\n            message=f\"{request_id}: {str(exc)}\",\n        )\n    except bgm_service.BgmServiceError as exc:\n        # 工具链或存储故障属于服务端问题，不能伪装成用户文件错误。日志保留\n        # request_id 和内部原因，HTTP 响应只返回稳定文案，避免暴露服务器路径。\n        logger.error(\n            f\"background music upload failed: request_id={request_id}, error={str(exc)}\"\n        )\n        raise HttpException(\n            task_id=request_id,\n            status_code=500,\n            message=f\"{request_id}: background music validation is unavailable\",\n        )\n\n    response = {\"file\": safe_filename}\n    return utils.get_response(200, response)\n\n@router.get(\n    \"/video_materials\", response_model=VideoMaterialRetrieveResponse, summary=\"Retrieve local video materials\"\n)\ndef get_video_materials_list(request: Request):\n    allowed_suffixes = (\"mp4\", \"mov\", \"avi\", \"flv\", \"mkv\", \"jpg\", \"jpeg\", \"png\")\n    local_videos_dir = utils.storage_dir(\"local_videos\", create=True)\n    files = []\n    for suffix in allowed_suffixes:\n        files.extend(glob.glob(os.path.join(local_videos_dir, f\"*.{suffix}\")))\n    # 文件系统枚举顺序不稳定，直接返回会导致“顺序拼接”在不同机器或不同","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/harry0703/MoneyPrinterTurbo/blob/1f9f19c2021a68d04df228f33e9099a0c947f6f8/app/controllers/v1/video.py#L346-L382","documentation":"Raised by the BGM upload endpoint when the service raises BgmServiceError: an infrastructure failure in the toolchain or storage, not a user mistake. Per the code comments, this must not masquerade as a user file error, so the endpoint returns 500 with a fixed message ('background music validation is unavailable') and keeps the internal reason (FFmpeg missing/failed, storage dir unwritable, timeout) only in error logs. The stable message also avoids leaking server paths.","triggerScenarios":"FFmpeg binary missing or not executable (e.g. imageio-ffmpeg package not installed); storage directory creation failing due to permissions; FFmpeg crashing with OSError; FFmpeg exceeding the validation timeout because the system is overloaded — each surfaces as this same 500.","commonSituations":"Deploying to a slim Docker image without the ffmpeg package; read-only volumes mounted at the BGM storage path; broken imageio-ffmpeg install after a dependency upgrade; disk-full or NFS hangs on the storage dir.","solutions":["Check server logs (logger.error line includes request_id and the real str(exc)) to identify the infrastructure cause.","Ensure FFmpeg is available to the server process — install the system ffmpeg package or verify imageio-ffmpeg is in the environment.","Verify the BGM upload directory exists and is writable by the service user.","Retry once after fixing the environment; if the cause was a validation timeout under load, retry when the machine is calmer."],"exampleFix":"# before: slim Dockerfile with no ffmpeg\n# FROM python:3.11-slim\n# RUN pip install -r requirements.txt\n\n# after\nFROM python:3.11-slim\nRUN apt-get update && apt-get install -y --no-install-recommends ffmpeg && rm -rf /var/lib/apt/lists/*\nRUN pip install -r requirements.txt","handlingStrategy":"fallback","validationCode":"# ops pre-flight on the server host\nimport shutil\nassert shutil.which(\"ffmpeg\") or importlib.util.find_spec(\"imageio_ffmpeg\"), \"no FFmpeg available\"\nimport os\nassert os.access(bgm_upload_dir, os.W_OK), \"BGM storage not writable\"","typeGuard":null,"tryCatchPattern":"try:\n    resp = upload_bgm(name, fh)\nexcept BgmServiceUnavailable:  # client mapping of the 500 stable message\n    notify_ops(\"background music validation is unavailable\")  # do NOT tell user to change the file\n    raise","preventionTips":["Include ffmpeg (or imageio-ffmpeg) in deployment images and verify in health checks.","Make the BGM storage directory writable and mounted on a healthy volume.","Watch server error logs — the real cause is only there, never in the HTTP response."],"tags":["ffmpeg","server-error","http-500","storage","bgm"],"backgroundTag":null,"analyzedSha":"1f9f19c2021a68d04df228f33e9099a0c947f6f8","analyzedAt":"2026-08-14T19:41:05.568Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}