{"record":{"id":"fc1573319a89d36e","repo":"unslothai/unsloth","slug":"a-reference-decoded-to-no-data","errorCode":null,"errorMessage":"A reference decoded to no data.","messagePattern":"A reference decoded to no data\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/inference/video.py","lineNumber":423,"sourceCode":"_MAX_REFERENCE_MEDIA_BYTES = 96 * 1024 * 1024\n\n\ndef _decode_b64_media(data: Optional[str]) -> bytes:\n    \"\"\"Decode a base64 media payload, optionally wrapped in a data URL.\"\"\"\n    import base64\n    import binascii\n\n    raw = (data or \"\").strip()\n    if not raw:\n        raise ValueError(\"A reference was sent empty.\")\n    if raw.startswith(\"data:\"):\n        _, _, raw = raw.partition(\",\")\n    try:\n        blob = base64.b64decode(raw, validate = False)\n    except (binascii.Error, ValueError) as exc:\n        raise ValueError(f\"Invalid base64 media data: {exc}\") from exc\n    if not blob:\n        raise ValueError(\"A reference decoded to no data.\")\n    if len(blob) > _MAX_REFERENCE_MEDIA_BYTES:\n        raise ValueError(\n            f\"A reference is too large ({len(blob) / 1e6:.0f} MB); the limit is \"\n            f\"{_MAX_REFERENCE_MEDIA_BYTES / 1e6:.0f} MB.\"\n        )\n    return blob\n\n\nclass _VideoGenerationCancelled(Exception):\n    \"\"\"Unwinds a denoise loop that has no cooperative interrupt (no step callback);\n    generate() maps it to the VIDEO_CANCELLED_MSG sentinel the routes 409 on.\"\"\"\n\n\n@contextlib.contextmanager\ndef _scheduler_step_progress(pipe: Any, on_step: Any):\n    \"\"\"Progress + cancellation for pipelines WITHOUT callback_on_step_end.\n\n    HunyuanVideo15Pipeline exposes no per-step callback, but every denoise step","sourceCodeStart":405,"sourceCodeEnd":441,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/video.py#L405-L441","documentation":"The reference payload was syntactically valid base64 but decoded to zero bytes (e.g. the empty string is technically valid base64). _decode_b64_media treats a zero-length blob as an error distinct from 'invalid base64' and from 'empty input', catching data URLs like 'data:image/png;base64,' whose payload part is blank.","triggerScenarios":"Sending a data URL whose comma-separated payload is empty, or a bare base64 of b'' (empty string). The earlier empty check only fires on whitespace-only input, so a well-formed wrapper around nothing reaches this branch.","commonSituations":"A UI that always emits the data-URL wrapper even for a missing file; canvas/ImageBlob.toDataURL() on an unrendered element; a truncated upload where the encoder produced the header but no body.","solutions":["Ensure the media blob is actually read and non-empty before encoding it.","Skip sending the reference entirely when the source file/blob is zero-length.","If the field is optional, omit the key rather than sending an empty wrapper."],"exampleFix":"# before\nref = f'data:image/png;base64,{b64}'  # b64 == '' for a missing file\n\n# after\nref = f'data:image/png;base64,{b64}' if b64 else None\n# and omit the field when ref is None","handlingStrategy":"validation","validationCode":"import base64\n\ndef decodes_to_data(ref: str | None) -> bool:\n    if not ref or not ref.strip():\n        return False\n    raw = ref.strip()\n    if raw.startswith('data:'):\n        raw = raw.partition(',')[2]\n    try:\n        return len(base64.b64decode(raw)) > 0\n    except Exception:\n        return False","typeGuard":"def nonempty_b64_payload(value: str) -> bool:\n    raw = value.strip()\n    if raw.startswith('data:'):\n        raw = raw.partition(',')[2]\n    return len(raw) > 0 and base64.b64decode(raw, validate=False) != b''","tryCatchPattern":"try:\n    blob = _decode_b64_media(ref)\nexcept ValueError as e:\n    if 'decoded to no data' in str(e):\n        ref = capture_fallback_or_none()  # re-capture the source media\n    else:\n        raise","preventionTips":["Check the source blob's byte length before encoding it.","Never emit the data-URL wrapper when the underlying read returned nothing.","Treat zero-byte uploads as 'no file provided' in the UI."],"tags":["video","base64","reference-media","validation"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}