{"record":{"id":"2181fa6f728a6067","repo":"golang/go","slug":"revision-is-shorter-than-canonical-expected-s","errorCode":null,"errorMessage":"revision is shorter than canonical (expected %s)","messagePattern":"revision is shorter than canonical \\(expected (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modfetch/coderepo.go","lineNumber":699,"sourceCode":"\t\t\tif _, ok := err.(*module.ModuleError); !ok {\n\t\t\t\tif _, ok := err.(*module.InvalidVersionError); !ok {\n\t\t\t\t\terr = &module.InvalidVersionError{Version: version, Pseudo: true, Err: err}\n\t\t\t\t}\n\t\t\t\terr = &module.ModuleError{Path: r.modPath, Err: err}\n\t\t\t}\n\t\t}\n\t}()\n\n\trev, err := module.PseudoVersionRev(version)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif rev != info.Short {\n\t\tswitch {\n\t\tcase strings.HasPrefix(rev, info.Short):\n\t\t\treturn fmt.Errorf(\"revision is longer than canonical (expected %s)\", info.Short)\n\t\tcase strings.HasPrefix(info.Short, rev):\n\t\t\treturn fmt.Errorf(\"revision is shorter than canonical (expected %s)\", info.Short)\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"does not match short name of revision (expected %s)\", info.Short)\n\t\t}\n\t}\n\n\tt, err := module.PseudoVersionTime(version)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif !t.Equal(info.Time.Truncate(time.Second)) {\n\t\treturn fmt.Errorf(\"does not match version-control timestamp (expected %s)\", info.Time.UTC().Format(module.PseudoVersionTimestampFormat))\n\t}\n\n\ttagPrefix := \"\"\n\tif r.codeDir != \"\" {\n\t\ttagPrefix = r.codeDir + \"/\"\n\t}\n","sourceCodeStart":681,"sourceCodeEnd":717,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modfetch/coderepo.go#L681-L717","documentation":"Same validatePseudoVersion comparison (coderepo.go:694-703). This branch fires when info.Short starts with the embedded rev — the pseudo-version carries a shorter hash than the VCS's canonical short name. A too-short hash is ambiguous (could collide with another commit) and non-canonical, so the resolver refuses it.","triggerScenarios":"Hand-editing a pseudo-version to truncate the hash; an older toolchain generated pseudo-versions with fewer hex digits than the current default (git has progressively lengthened default short hashes over time); abbreviated hashes from a non-git VCS bridge.","commonSituations":"Pseudo-versions produced by old `go` versions when git's default abbrev was 7; repos where default abbrev grew to 12 after more commits; manual shortening for brevity.","solutions":["Regenerate the version with the current toolchain: `go get <module>@<commit>` and let it embed the correct short hash.","If the underlying repo's abbrev grew, update go.mod/go.sum to the re-derived pseudo-version.","Avoid hand-truncating hashes in version strings."],"exampleFix":"// before (7-char hash, no longer canonical)\nrequire example.com/m v0.0.0-20240101120000-e3702bed\n\n// after (current default short hash)\nrequire example.com/m v0.0.0-20240101120000-e3702bed3d42","handlingStrategy":"validation","validationCode":"// Reject pseudo-versions whose embedded hash is shorter than canonical.\n// bash:\n//   short=$(git rev-parse --short <commit>)\n//   # if the pseudo-version's hash field is shorter than ${#short}, regenerate it\n//\n// Go:\npackage main\nimport (\"golang.org/x/mod/module\"; \"strings\")\nfunc validateLen(pseudo, canonicalShort string) error {\n    rev, err := module.PseudoVersionRev(pseudo)\n    if err != nil { return err }\n    if len(rev) < len(canonicalShort) {\n        return fmt.Errorf(\"pseudo-version rev %s shorter than canonical %s\", rev, canonicalShort)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Regenerate pseudo-versions whenever the source VCS's default abbrev length grows.","Use `go get <module>@<commit>` for any new dependency pin.","Avoid truncating hashes for readability."],"tags":["go-modules","pseudo-version","vcs-revision","validation"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}