{"record":{"id":"e31bc5fbe766ed73","repo":"t8y2/dbx","slug":"versioned-agent-artifact-already-exists-target","errorCode":null,"errorMessage":"Versioned agent artifact already exists: {target}","messagePattern":"Versioned agent artifact already exists: (.+?)","errorType":"exception","errorClass":"FileExistsError","httpStatus":null,"severity":"error","filePath":"agents/scripts/version_agent_artifacts.py","lineNumber":22,"sourceCode":"from pathlib import Path\n\n\nNATIVE_DRIVERS = (\"cassandra\", \"hive\", \"argo\", \"oracle\", \"xugu\", \"kingbase\", \"iotdb\", \"neo4j\", \"vastbase\", \"duckdb\", \"rabbitmq\", \"rocketmq\", \"zookeeper\", \"tdengine\", \"etcd\", \"etcd2\", \"sqlite-worker\")\nPLATFORMS = (\n    \"macos-aarch64\",\n    \"macos-x64\",\n    \"linux-aarch64\",\n    \"linux-x64\",\n    \"windows-aarch64\",\n    \"windows-x64\",\n)\n\n\ndef rename_artifact(source: Path, target: Path) -> Path | None:\n    if not source.exists():\n        return None\n    if target.exists():\n        raise FileExistsError(f\"Versioned agent artifact already exists: {target}\")\n    source.rename(target)\n    return target\n\n\ndef version_agent_artifacts(release_dir: Path, versions: dict[str, str]) -> list[Path]:\n    renamed: list[Path] = []\n    for driver, version in sorted(versions.items()):\n        jar = rename_artifact(\n            release_dir / f\"dbx-agent-{driver}.jar\",\n            release_dir / f\"dbx-agent-{driver}-{version}.jar\",\n        )\n        if jar:\n            renamed.append(jar)\n\n    for driver in NATIVE_DRIVERS:\n        version = versions.get(driver)\n        if not version:\n            raise ValueError(f\"Missing version for native driver: {driver}\")","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/scripts/version_agent_artifacts.py#L4-L40","documentation":"rename_artifact refuses to overwrite files: when the versioned target path (e.g. dbx-agent-<driver>-<version>-<platform>) already exists in the release directory it raises FileExistsError. This protects previously published versioned artifacts from being silently clobbered by a re-run of the versioning script.","triggerScenarios":"Calling version_agent_artifacts() (or rename_artifact() directly) on a release_dir that already contains an artifact with the target versioned name — typically because the script was run twice for the same version.","commonSituations":"Re-running a release job after a partial failure; rebuilding the same release version without cleaning the output directory; a stale artifact left over from a previous build of the identical version.","solutions":["Delete the existing target artifact (or clean the release_dir) and re-run the versioning script","Use a new/unique version number so the target filename does not exist","Wrap the call in try/except FileExistsError and skip or log when the artifact is already versioned"],"exampleFix":"// before\nrename_artifact(release_dir / \"dbx-agent-hive-linux\", release_dir / \"dbx-agent-hive-1.2.0-linux\")\n// after\nif not (release_dir / \"dbx-agent-hive-1.2.0-linux\").exists():\n    rename_artifact(release_dir / \"dbx-agent-hive-linux\", release_dir / \"dbx-agent-hive-1.2.0-linux\")","handlingStrategy":"try-catch","validationCode":"target = release_dir / f\"dbx-agent-{driver}-{version}-{platform}\"\nif target.exists():\n    target.unlink()  # or pick a new version","typeGuard":null,"tryCatchPattern":"try:\n    version_agent_artifacts(release_dir, versions)\nexcept FileExistsError as e:\n    logger.info(\"already versioned: %s\", e); skip","preventionTips":["Clean the release directory at the start of each build","Use unique versions per build; never re-publish an existing version","Make release jobs idempotent by treating FileExistsError as 'already done'"],"tags":["python","filesystem","release-automation","file-exists"],"backgroundTag":"file-already-exists","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}