{"record":{"id":"2d38cea2fdf01161","repo":"reflex-dev/reflex","slug":"failed-to-create-temp-directory-for-download-ose","errorCode":null,"errorMessage":"Failed to create temp directory for download: {ose}","messagePattern":"Failed to create temp directory for download: (.+?)","errorType":"exception","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"reflex/utils/templates.py","lineNumber":132,"sourceCode":"def create_config_init_app_from_remote_template(app_name: str, template_url: str):\n    \"\"\"Create new rxconfig and initialize app using a remote template.\n\n    Args:\n        app_name: The name of the app.\n        template_url: The path to the template source code as a zip file.\n\n    Raises:\n        SystemExit: If any download, file operations fail or unexpected zip file format.\n\n    \"\"\"\n    import httpx\n\n    # Create a temp directory for the zip download.\n    try:\n        temp_dir = tempfile.mkdtemp()\n    except OSError as ose:\n        logger.error(f\"Failed to create temp directory for download: {ose}\")\n        raise SystemExit(1) from None\n\n    # Use httpx GET with redirects to download the zip file.\n    zip_file_path: Path = Path(temp_dir) / \"template.zip\"\n    try:\n        # Note: following redirects can be risky. We only allow this for reflex built templates at the moment.\n        response = net.get(template_url, follow_redirects=True)\n        logger.debug(f\"Server responded download request: {response}\")\n        response.raise_for_status()\n    except httpx.HTTPError as he:\n        logger.error(f\"Failed to download the template: {he}\")\n        raise SystemExit(1) from None\n    try:\n        zip_file_path.write_bytes(response.content)\n        logger.debug(f\"Downloaded the zip to {zip_file_path}\")\n    except OSError as ose:\n        logger.error(f\"Unable to write the downloaded zip to disk {ose}\")\n        raise SystemExit(1) from None\n","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/reflex/utils/templates.py#L114-L150","documentation":"Raised by `create_config_init_app_from_remote_template` when `tempfile.mkdtemp()` fails with an OSError while preparing a scratch directory for the template zip download. The `raise SystemExit(1) from None` aborts the `reflex init` flow; the underlying OSError text is included in the log line.","triggerScenarios":"Creating a new app from a remote template (reflex init with a template URL) on a system where the temp directory (TMPDIR/TMP/TEMP or /tmp) is unwritable, full, or missing; mkdtemp raising PermissionError/NoSpaceError (subclasses of OSError).","commonSituations":"Read-only or full /tmp in containers and CI; TMPDIR pointing to a nonexistent directory; sandboxed environments restricting filesystem writes; disk quota exceeded.","solutions":["Check disk space (df -h) and free space if the temp volume is full.","Verify TMPDIR is set to an existing, writable directory, or set it explicitly: TMPDIR=$HOME/tmp reflex init.","If in a container, ensure /tmp is mounted writable."],"exampleFix":"# no code fix; environment fix\n# before: TMPDIR=/nonexistent reflex init --template-url ...\n# after:  mkdir -p $HOME/tmp && TMPDIR=$HOME/tmp reflex init --template-url ...","handlingStrategy":"fallback","validationCode":"import os, tempfile\n\ndef temp_writable() -> bool:\n    try:\n        tempfile.mkdtemp()\n        return True\n    except OSError:\n        return False\n\n# or pre-flight: os.access(os.environ.get(\"TMPDIR\", \"/tmp\"), os.W_OK)","typeGuard":null,"tryCatchPattern":"try:\n    create_config_init_app_from_remote_template(...)\nexcept SystemExit:\n    # inspect logs; retry with TMPDIR pointed at a writable location\n    os.environ[\"TMPDIR\"] = os.path.expanduser(\"~/tmp\")\n    create_config_init_app_from_remote_template(...)","preventionTips":["Pre-check disk space and TMPDIR writability in CI before running reflex init.","Mount /tmp as writable tmpfs with adequate size in containers.","Set TMPDIR explicitly in constrained environments."],"tags":["reflex","templates","tempdir","permissions","disk-full"],"backgroundTag":"temp-directory-creation-failed","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}