{"record":{"id":"841bdf83d517fa24","repo":"golang-migrate/migrate","slug":"unable-to-parse-file-v-841bdf","errorCode":null,"errorMessage":"unable to parse file %v","messagePattern":"unable to parse file (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"source/bitbucket/bitbucket.go","lineNumber":116,"sourceCode":"\t\tRepoSlug: b.config.Repo,\n\t\tRef:      b.config.Ref,\n\t\tPath:     b.config.Path,\n\t}\n\n\tdirContents, err := b.client.Repositories.Repository.ListFiles(fOpt)\n\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tfor _, fi := range dirContents {\n\n\t\tm, err := source.DefaultParse(filepath.Base(fi.Path))\n\t\tif err != nil {\n\t\t\tcontinue // ignore files that we can't parse\n\t\t}\n\t\tif !b.migrations.Append(m) {\n\t\t\treturn fmt.Errorf(\"unable to parse file %v\", fi.Path)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (b *Bitbucket) ensureFields() {\n\tif b.config == nil {\n\t\tb.config = &Config{}\n\t}\n}\n\nfunc (b *Bitbucket) Close() error {\n\treturn nil\n}\n\nfunc (b *Bitbucket) First() (version uint, er error) {\n\tb.ensureFields()","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/source/bitbucket/bitbucket.go#L98-L134","documentation":"readDirectory parses each file returned by the Bitbucket ListFiles API with source.DefaultParse. Unparseable names are skipped, but if a name parses and migrations.Append still returns false — which only happens when another migration with the same version was already appended — the driver aborts with 'unable to parse file %v'. Despite the wording, the actual cause is a duplicate migration version, not a parse failure.","triggerScenarios":"bitbucket.WithInstance/Open where the repo listing contains two files whose basenames yield the same version, e.g. `1_foo.up.sql` and `001_bar.up.sql`, or the same filename present via path casing differences.","commonSituations":"Zero-padding inconsistencies between team members' created migrations; a migration cherry-picked or merged twice from branches; renamed file keeping an old version prefix.","solutions":["Find the duplicate version: list repo files and compute version prefixes; rename or delete one of the colliding migrations.","Standardize on zero-padded seq prefixes (e.g. 000001_) so `1_` and `001_` no longer collide after parsing.","Use `migrate create` for every new migration so versions are generated uniquely instead of hand-written.","Fix the branch history (rebase/dedupe) if the same migration was merged twice, then retry."],"exampleFix":"// before\nmigrations/1_add_users.up.sql\nmigrations/001_add_users_v2.up.sql  // same parsed version 1\n// after\nmigrations/000001_add_users.up.sql\nmigrations/000002_add_users_v2.up.sql","handlingStrategy":"validation","validationCode":"// fetch file list and check for duplicate versions before WithInstance\nseen := map[uint64]string{}\nfor _, fi := range dirContents {\n    m, err := source.DefaultParse(filepath.Base(fi.Path))\n    if err != nil {\n        continue\n    }\n    if prev, dup := seen[m.Version]; dup {\n        return fmt.Errorf(\"duplicate version %d: %s and %s\", m.Version, prev, fi.Path)\n    }\n    seen[m.Version] = fi.Path\n}","typeGuard":null,"tryCatchPattern":"d, err := bitbucket.WithInstance(cl, cfg)\nif err != nil && strings.HasPrefix(err.Error(), \"unable to parse file\") {\n    f := strings.TrimPrefix(err.Error(), \"unable to parse file \")\n    return fmt.Errorf(\"duplicate migration version detected for %s; dedupe and retry\", f)\n}","preventionTips":["Always create migrations with `migrate create` to get unique versions.","Use zero-padded seq prefixes consistently (000001_).","Check PR diffs for duplicate version prefixes in CI.","Rebase/dedupe branches before merging the same migration twice."],"tags":["bitbucket","migrations","duplicate","versioning"],"backgroundTag":"duplicate-migration-version","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}