{"record":{"id":"78f79b83f3927e61","repo":"cockroachdb/cockroach","slug":"cannot-have-two-files-with-the-same-basename-in-di","errorCode":null,"errorMessage":"cannot have two files with the same basename in DISTDIR_FILES","messagePattern":"cannot have two files with the same basename in DISTDIR_FILES","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/generate-distdir/main.go","lineNumber":342,"sourceCode":"\tif err := getShasFromDepsBzl(src.depsBzl, ret); err != nil {\n\t\treturn nil, err\n\t}\n\tif err := getShasFromWorkspace(src.workspace, ret); err != nil {\n\t\treturn nil, err\n\t}\n\tif err := getShasFromArchivedCdeps(src.cdepsArchivedBzl, src.cdepsRepositoriesBzl, ret); err != nil {\n\t\treturn nil, err\n\t}\n\treturn ret, nil\n}\n\nfunc dumpOutput(shas map[string]string) {\n\tbases := make(map[string]interface{})\n\tfor url := range shas {\n\t\tbase := path.Base(url)\n\t\t_, ok := bases[base]\n\t\tif ok {\n\t\t\tpanic(\"cannot have two files with the same basename in DISTDIR_FILES\")\n\t\t}\n\t\tbases[base] = nil\n\t}\n\n\tfmt.Println(`# Code generated by generate-distdir. DO NOT EDIT.\n\nDISTDIR_FILES = {`)\n\turls := make([]string, 0, len(shas))\n\tfor url := range shas {\n\t\turls = append(urls, url)\n\t}\n\tsort.Strings(urls)\n\tfor _, url := range urls {\n\t\tfmt.Printf(`    \"%s\": \"%s\",\n`, url, shas[url])\n\t}\n\tfmt.Println(\"}\")\n}","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/cockroachdb/cockroach/blob/8812064a015d2faf99d3fc7e15880f94042954b0/pkg/cmd/generate-distdir/main.go#L324-L360","documentation":"generate-distdir builds the DISTDIR_FILES mapping used by bazel's distdir mechanism; dumpOutput panics when two entries have the same path.Base() because distdir fetches and stores artifacts by basename — a collision would silently overwrite one file with another. This is a deliberate fail-fast at generation time.","triggerScenarios":"Adding a cdep/repository whose artifact URL ends in the same filename as an existing entry — e.g. two dependencies both publishing 'v1.2.3.tar.gz' from different hosts, or a mirror URL that only differs in directory.","commonSituations":"Bumping or adding third-party Go/C++ dependencies in cockroach; upstream repackaging artifacts under generic names; switching a dependency to a mirror that strips the prefixed filename.","solutions":["Identify the colliding pair: list the URLs feeding DISTDIR_FILES and group by path.Base()","Point one dependency at a uniquely named artifact (upstream asset with a prefixed name, or a renamed mirror copy)","Regenerate the file with `bazel run //pkg/cmd/generate-distdir` and commit the result"],"exampleFix":"# before: two entries both named v1.0.0.tar.gz\nhttps://mirror.example.com/somelib/v1.0.0.tar.gz\nhttps://other.example.com/otherlib/v1.0.0.tar.gz\n\n# after: mirror one artifact under a unique basename\nhttps://mirror.example.com/somelib/v1.0.0.tar.gz\nhttps://other.example.com/otherlib/otherlib-v1.0.0.tar.gz","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["When adding a dependency, choose artifact URLs with unique basenames","Run generate-distdir immediately after dependency bumps so collisions surface in CI","Prefer upstream release assets that embed the project name in the filename"],"tags":["build","bazel","distdir","dependencies","go"],"backgroundTag":null,"analyzedSha":"8812064a015d2faf99d3fc7e15880f94042954b0","analyzedAt":"2026-08-15T16:34:17.351Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}