{"record":{"id":"1e607b7cafe8186d","repo":"jamiepine/voicebox","slug":"invalid-json-in-archive-e","errorCode":null,"errorMessage":"Invalid JSON in archive: {e}","messagePattern":"Invalid JSON in archive: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/services/export_import.py","lineNumber":238,"sourceCode":"                \n                try:\n                    # Add sample to profile\n                    await add_profile_sample(\n                        profile.id,\n                        tmp_path,\n                        reference_text,\n                        db,\n                    )\n                finally:\n                    # Clean up temp file\n                    Path(tmp_path).unlink(missing_ok=True)\n            \n            return profile\n            \n    except zipfile.BadZipFile:\n        raise ValueError(\"Invalid ZIP file\")\n    except json.JSONDecodeError as e:\n        raise ValueError(f\"Invalid JSON in archive: {e}\")\n    except Exception as e:\n        if isinstance(e, ValueError):\n            raise\n        raise ValueError(f\"Error importing profile: {str(e)}\")\n\n\ndef export_generation_to_zip(generation_id: str, db: Session) -> bytes:\n    \"\"\"\n    Export a generation to a ZIP archive.\n    \n    Args:\n        generation_id: Generation ID to export\n        db: Database session\n        \n    Returns:\n        ZIP file contents as bytes\n        \n    Raises:","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/jamiepine/voicebox/blob/51f49dea198384b4eb6087b72c17057c6eb1c1cd/backend/services/export_import.py#L220-L256","documentation":"Raised inside the profile import's try block when json.loads() on manifest.json or samples.json throws json.JSONDecodeError. The ZIP itself opens fine, but one of the metadata files inside is not valid JSON (export_import.py:237-238). Wrapped as ValueError(f\"Invalid JSON in archive: {e}\") with the parser's positional detail preserved.","triggerScenarios":"manifest.json or samples.json contains trailing commas, single quotes, comments, or was hand-edited; the file is UTF-16 with a BOM; the file was overwritten by a stray zip entry that is actually audio/text; partial write during a crash left a truncated JSON document.","commonSituations":"User edited an exported ZIP by hand to rename a profile; an older or newer export format writes a different schema; a sync tool (Dropbox/OneDrive) uploaded a conflicted copy into the archive; export was interrupted and wrote a partial JSON file.","solutions":["Unzip the archive locally and run python -m json.tool manifest.json to find the exact syntax error — the {e} suffix reports line/column.","Re-export the profile from the source instance rather than hand-editing the archive.","If migrating across versions, open the ZIP, fix the JSON in place, and rezip preserving the same internal paths (manifest.json, samples.json, samples/*.wav).","Check for a BOM: strip leading \\ufeff from manifest.json before re-zipping."],"exampleFix":"# before: hand-edited manifest with trailing comma\n{\"version\": 1, \"profile\": {\"name\": \"x\",},}\n# after: valid JSON\n{\"version\": 1, \"profile\": {\"name\": \"x\"}}","handlingStrategy":"validation","validationCode":"import json, zipfile, io\n\ndef validate_archive_json(file_bytes: bytes) -> None:\n    with zipfile.ZipFile(io.BytesIO(file_bytes)) as z:\n        for name in ('manifest.json', 'samples.json'):\n            if name not in z.namelist():\n                raise ValueError(f'missing {name}')\n            try:\n                json.loads(z.read(name))\n            except json.JSONDecodeError as e:\n                raise ValueError(f'{name} is not valid JSON: {e}')","typeGuard":"null","tryCatchPattern":"try:\n    profile = await import_profile_from_bytes(file_bytes, db)\nexcept ValueError as e:\n    msg = str(e)\n    if msg.startswith('Invalid JSON in archive'):\n        raise HTTPException(400, 'Archive metadata is malformed JSON. Re-export the profile.')\n    raise HTTPException(400, msg)","preventionTips":["Never hand-edit JSON inside an export archive; re-export instead.","Run python -m json.tool on extracted manifest/samples files before re-zipping.","Keep exporter and importer on the same schema version."],"tags":["json","import","validation","manifest"],"backgroundTag":null,"analyzedSha":"51f49dea198384b4eb6087b72c17057c6eb1c1cd","analyzedAt":"2026-08-12T16:51:42.824Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}