{"record":{"id":"a395390690edf35f","repo":"jamiepine/voicebox","slug":"error-importing-generation-str-e","errorCode":null,"errorMessage":"Error importing generation: {str(e)}","messagePattern":"Error importing generation: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/services/export_import.py","lineNumber":461,"sourceCode":"                    \"id\": db_generation.id,\n                    \"profile_id\": profile_id,\n                    \"profile_name\": profile_name,\n                    \"text\": db_generation.text,\n                    \"message\": f\"Generation imported successfully (assigned to profile: {profile_name})\"\n                }\n                \n            finally:\n                # Clean up temp file\n                Path(tmp_path).unlink(missing_ok=True)\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 generation: {str(e)}\")\n","sourceCodeStart":443,"sourceCodeEnd":462,"githubUrl":"https://github.com/jamiepine/voicebox/blob/51f49dea198384b4eb6087b72c17057c6eb1c1cd/backend/services/export_import.py#L443-L462","documentation":"Catch-all for the generation import path: any non-BadZipFile, non-JSONDecodeError, non-ValueError exception inside the with-zipfile block is normalized into ValueError(f\"Error importing generation: {str(e)}\") (export_import.py:458-461). ValueError subclasses (including the manifest/audio/profile precondition checks above) are re-raised verbatim by the isinstance(e, ValueError) guard.","triggerScenarios":"shutil.copy fails (disk full / permission denied writing to generations_dir); DBGeneration insert raises sqlalchemy IntegrityError (duplicate id from a UUID collision or re-import without new id); config.get_generations_dir() returns an unwritable path; config.to_storage_path raises.","commonSituations":"Storage volume full; UUID collision from importing the same generation twice with deterministic IDs (the importer generates fresh UUIDs so this is unlikely unless the code was patched); permission issues on the generations directory.","solutions":["Inspect the {str(e)} tail to identify the underlying exception type and message.","If OSError/PermissionError: check write permissions and free space on config.get_generations_dir().","If sqlalchemy IntegrityError: check for a duplicate generation id and ensure the importer uses str(uuid4()) (it does in stock code).","If config.to_storage_path fails, verify the storage root is configured and absolute."],"exampleFix":"# before: generations dir not writable\n# after: point config at a writable dir\nexport GENERATIONS_DIR=/var/lib/voicebox/generations","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try:\n    result = await import_generation_from_bytes(file_bytes, db)\nexcept ValueError as e:\n    msg = str(e)\n    if msg.startswith('Error importing generation:'):\n        logger.exception('generation import failed: %s', msg)\n        raise HTTPException(500, 'Generation import failed; see server logs.')\n    raise HTTPException(400, msg)","preventionTips":["Ensure config.get_generations_dir() exists and is writable before enabling imports.","Monitor free disk space; shutil.copy fails fast on ENOSPC.","Wrap the import in a transaction so a failed DB insert rolls back cleanly.","Log the underlying exception chain, not just the wrapped ValueError."],"tags":["import","catch-all","filesystem","generation","database"],"backgroundTag":null,"analyzedSha":"51f49dea198384b4eb6087b72c17057c6eb1c1cd","analyzedAt":"2026-08-12T16:51:42.824Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}