{"record":{"id":"721ca5bbe19a385d","repo":"unslothai/unsloth","slug":"could-not-import-entry-repo-e","errorCode":null,"errorMessage":"Could not import '{entry['repo']}': {e}","messagePattern":"Could not import '(.+?)': (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":502,"severity":"error","filePath":"studio/backend/routes/training.py","lineNumber":4272,"sourceCode":"                folder.mkdir(parents = True, exist_ok = True)\n                for moved, original in folded:\n                    try:\n                        if moved.exists() and not original.exists():\n                            shutil.move(str(moved), str(original))\n                    except OSError:\n                        # Best effort: one unrestorable entry must not mask the original failure.\n                        pass\n\n            try:\n                try:\n                    if entry[\"loader\"] == \"imagefolder_jsonl\":\n                        imported = _materialize_imagefolder_jsonl(entry, staging, cap)\n                    else:\n                        imported = _materialize_hf_dataset(entry, staging, cap)\n                except HTTPException:\n                    raise\n                except Exception as e:  # noqa: BLE001 -- surface a readable fetch/parse failure\n                    raise HTTPException(\n                        status_code = 502,\n                        detail = f\"Could not import '{entry['repo']}': {e}\",\n                    )\n                if imported == 0:\n                    raise HTTPException(\n                        status_code = 502,\n                        detail = f\"No images found in '{entry['repo']}'.\",\n                    )\n                # Promote the fully-materialized staging dir as a UNIT: a same-filesystem rename is atomic, so a hard process death\n                # leaves either the old folder or the finished import. rmdir needs an empty target, so fold any pre-existing files (a .thumbs cache, an older metadata.jsonl) INTO staging first and keep one atomic promotion.\n                try:\n                    for p in sorted(folder.iterdir()):\n                        # Same name in both: the imported file wins, as the previous per-file move did. Park the old one in the rescue dir so the folder can be emptied for the rename without destroying it.\n                        dest = (rescue if (staging / p.name).exists() else staging) / p.name\n                        shutil.move(str(p), str(dest))\n                        folded.append((dest, p))\n                    os.rmdir(folder)\n                    os.replace(str(staging), str(folder))","sourceCodeStart":4254,"sourceCodeEnd":4290,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/routes/training.py#L4254-L4290","documentation":"HTTP 502 from the import route: the materialization step (_materialize_imagefolder_jsonl or _materialize_hf_dataset) raised a non-HTTP exception — a network failure, HF auth/availability error, JSONL parse error, disk error — which is wrapped into a readable message including the underlying exception text. The staging directory is cleaned up; nothing partial is promoted.","triggerScenarios":"Any unexpected exception while fetching/parsing the upstream dataset: Hugging Face connection reset or 429 rate limit, gated repo requiring a token, malformed metadata.jsonl in an imagefolder repo, or a local OSError while writing staging files. HTTPExceptions from deeper checks (e.g. 1354/1355) are re-raised untouched.","commonSituations":"Flaky network to huggingface.co; rate limiting during bulk imports; gated/private repos without configured credentials; upstream repo files renamed/removed; disk full while staging.","solutions":["Read the embedded {e} — it names the real cause; fix that first (network, HF token via huggingface-cli login, disk space).","Retry the import after transient network/429 errors — materialization is fully re-started from staging, so retries are safe.","If the repo is gated or moved, pick another example or update Studio's curated list."],"exampleFix":"# authenticate for gated HF repos before importing\nhuggingface-cli login\ndf -h /studio/datasets   # ensure staging space","handlingStrategy":"retry","validationCode":"import socket, urllib.request\n\ndef hf_reachable() -> bool:\n    try:\n        urllib.request.urlopen('https://huggingface.co', timeout=5)\n        return True\n    except OSError:\n        return False","typeGuard":"def is_import_wrapped_failure(exc: HTTPException) -> bool:\n    return exc.status_code == 502 and str(exc.detail).startswith(\"Could not import\")","tryCatchPattern":"for attempt in range(3):\n    try:\n        resp = await api.importExample(ex.id)\n        break\n    except HTTPStatusError as e:\n        if e.response.status_code == 502 and 'Could not import' in e.response.text:\n            await backoff(attempt)  # transient HF/network errors are common\n            continue\n        raise","preventionTips":["Distinguish transient (network/429) from permanent (gated/renamed repo) causes via the embedded message before retrying.","Authenticate huggingface-cli for gated curated repos.","Keep disk headroom: staging duplicates the import's bytes."],"tags":["huggingface","network","import","http-502","upstream"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}