{"record":{"id":"92eae473335de5f8","repo":"langchain-ai/deepagents","slug":"source-invalid-zip-file","errorCode":null,"errorMessage":"{source}: invalid zip file","messagePattern":"(.+?): invalid zip file","errorType":"exception","errorClass":"FleetImportError","httpStatus":null,"severity":"error","filePath":"libs/talon/deepagents_talon/fleet_import.py","lineNumber":158,"sourceCode":"    target = target_dir.expanduser()\n    home = assistant_home.expanduser() if assistant_home is not None else target\n    try:\n        with zipfile.ZipFile(source) as archive:\n            entries = _validated_entries(archive)\n            if \"AGENTS.md\" not in entries:\n                msg = \"AGENTS.md: missing required root prompt\"\n                raise FleetImportError(msg)\n            with tempfile.TemporaryDirectory(prefix=\"deepagents-talon-import-\") as raw:\n                staging = Path(raw)\n                _materialize_staging(archive, entries, staging)\n                summaries = _mcp_summaries(staging, source)\n                notes = _format_setup_notes(source.name, summaries)\n                mcp_config = _format_mcp_config(summaries)\n                config_ignored = (staging / \"config.json\").is_file()\n                _refresh_target(staging, target, home, notes, mcp_config)\n    except zipfile.BadZipFile as exc:\n        msg = f\"{source}: invalid zip file\"\n        raise FleetImportError(msg) from exc\n    except OSError as exc:\n        msg = f\"{target}: {exc}\"\n        raise FleetImportError(msg) from exc\n\n    return FleetImportResult(\n        target_dir=target,\n        root_prompt_count=1,\n        subagent_prompt_count=len(_subagent_prompt_paths(home)),\n        config_ignored=config_ignored,\n        mcp_notes=notes,\n        interrupt_tools=tuple(\n            sorted({tool for summary in summaries for tool in summary.interrupt_tools})\n        ),\n    )\n\n\ndef format_import_stdout(result: FleetImportResult) -> str:\n    \"\"\"Render a concise user-facing import summary.","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/talon/deepagents_talon/fleet_import.py#L140-L176","documentation":"FleetImportError raised by `import_fleet_zip` when the source file cannot be opened as a zip archive. `zipfile.ZipFile(source)` raises BadZipFile, which is caught and re-raised as `FleetImportError(f\"{source}: invalid zip file\")` with the original exception chained. This is a fail-fast replacement for the stdlib exception.","triggerScenarios":"Passing a path that is not a zip (plain text, tar.gz, truncated download, empty file) to `import_fleet_zip`. The `zipfile.BadZipFile` handler at libs/talon/deepagents_talon/fleet_import.py:157 converts it.","commonSituations":"Download interrupted leaving a truncated/corrupt archive; renaming a .tar.gz to .zip; pointing at a directory or text file by mistake; zip produced with an unsupported legacy format.","solutions":["Verify the file is a valid zip: `python -m zipfile -t fleet.zip` or `unzip -t fleet.zip`.","Re-export or re-download the archive; ensure it is a real zip, not tar.gz.","Check the file is non-empty and not an HTML error page saved by a failed download (`file fleet.zip`)."],"exampleFix":"// before\nimport_fleet_zip(Path(\"fleet.tar.gz\"), target)\n// after (convert first)\nsubprocess.run([\"tar\", \"-xzf\", \"fleet.tar.gz\"]); \nsubprocess.run([\"zip\", \"-r\", \"fleet.zip\", \".\"], cwd=\"extracted\")\nimport_fleet_zip(Path(\"fleet.zip\"), target)","handlingStrategy":"validation","validationCode":"import zipfile\ndef is_valid_zip(path) -> bool:\n    try:\n        with zipfile.ZipFile(path) as z:\n            return z.testzip() is None\n    except (zipfile.BadZipFile, OSError):\n        return False","typeGuard":null,"tryCatchPattern":"from deepagents_talon.fleet_import import import_fleet_zip, FleetImportError\ntry:\n    result = import_fleet_zip(source, target)\nexcept FleetImportError as exc:\n    if \"invalid zip file\" in str(exc):\n        raise SystemExit(f\"re-download or re-export {source}; it is not a valid zip\") from exc\n    raise","preventionTips":["Verify downloads (checksum/size) before importing.","Do not rename tar.gz to zip; convert or re-export as real zip.","Use `unzip -t` or `python -m zipfile -t` as a pre-import sanity check."],"tags":["import","zip","file-format","corrupt-file"],"backgroundTag":"invalid-zip-file","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}