{"record":{"id":"cde00d3d1286dfa1","repo":"golang-migrate/migrate","slug":"unable-to-parse-file-v-cde00d","errorCode":null,"errorMessage":"unable to parse file %v","messagePattern":"unable to parse file (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"source/google_cloud_storage/storage.go","lineNumber":61,"sourceCode":"\t\treturn nil, err\n\t}\n\treturn &driver, nil\n}\n\nfunc (g *gcs) loadMigrations() error {\n\titer := g.bucket.Objects(context.Background(), &storage.Query{\n\t\tPrefix:    g.prefix,\n\t\tDelimiter: \"/\",\n\t})\n\tobject, err := iter.Next()\n\tfor ; err == nil; object, err = iter.Next() {\n\t\t_, fileName := path.Split(object.Name)\n\t\tm, parseErr := source.DefaultParse(fileName)\n\t\tif parseErr != nil {\n\t\t\tcontinue\n\t\t}\n\t\tif !g.migrations.Append(m) {\n\t\t\treturn fmt.Errorf(\"unable to parse file %v\", object.Name)\n\t\t}\n\t}\n\tif err != iterator.Done {\n\t\treturn err\n\t}\n\treturn nil\n}\n\nfunc (g *gcs) Close() error {\n\treturn nil\n}\n\nfunc (g *gcs) First() (uint, error) {\n\tv, ok := g.migrations.First()\n\tif !ok {\n\t\treturn 0, os.ErrNotExist\n\t}\n\treturn v, nil","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/source/google_cloud_storage/storage.go#L43-L79","documentation":"Raised by the Google Cloud Storage driver's loadMigrations when an object's filename parses as a migration but its version number duplicates one already appended (Append returns false). Filenames that fail source.DefaultParse are skipped silently; the error only fires for duplicate versions among parseable object names.","triggerScenarios":"loadMigrations (invoked from Open and from tests) iterating a GCS bucket where two objects resolve to the same migration version.","commonSituations":"Bucket containing backup copies of migrations (e.g. uploaded twice, or with timestamps in metadata), merged branches both adding migration NNN, or objects copied between environments with colliding version numbers.","solutions":["gsutil ls gs://bucket/prefix and identify filenames with duplicate version numbers","Rename or delete duplicate/backup objects so each version is unique","Re-upload the cleaned migration set and re-run the migration tool"],"exampleFix":"// before (bucket objects)\nmigrations/002_create_users.sql\nmigrations/002_create_users(1).sql\n// after — delete the duplicate upload\nmigrations/002_create_users.sql","handlingStrategy":"validation","validationCode":"it := client.Bucket(bucket).Objects(ctx, &storage.Query{Prefix: prefix})\nseen := map[uint]string{}\nfor {\n    obj, err := it.Next()\n    if err == iterator.Done { break }\n    if err != nil { return err }\n    m, perr := source.DefaultParse(path.Base(obj.Name))\n    if perr != nil { continue }\n    if prev, dup := seen[m.Version]; dup {\n        return fmt.Errorf(\"duplicate version %d: %s vs %s\", m.Version, prev, obj.Name)\n    }\n    seen[m.Version] = obj.Name\n}","typeGuard":null,"tryCatchPattern":"if err := loadMigrations(ctx); err != nil {\n    if strings.HasPrefix(err.Error(), \"unable to parse file\") {\n        return fmt.Errorf(\"duplicate migration versions in GCS bucket: %w\", err)\n    }\n    return err\n}","preventionTips":["Keep the bucket path migrations-only; separate prefixes per environment","CI or deploy-time lint of bucket object names for unique versions","Avoid manual re-uploads that create duplicate copies","Use lifecycle rules to clean stale objects"],"tags":["gcs","google-cloud","migration","duplicate"],"backgroundTag":"duplicate-migration-version","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}