{"record":{"id":"30bf488957e8a02a","repo":"golang/go","slug":"revision-is-longer-than-canonical-expected-s","errorCode":null,"errorMessage":"revision is longer than canonical (expected %s)","messagePattern":"revision is longer than canonical \\(expected (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modfetch/coderepo.go","lineNumber":697,"sourceCode":"\tdefer func() {\n\t\tif err != nil {\n\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 + \"/\"","sourceCodeStart":679,"sourceCodeEnd":715,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modfetch/coderepo.go#L679-L715","documentation":"validatePseudoVersion (coderepo.go:694-703) compares the commit hash embedded in a pseudo-version against info.Short, the VCS's canonical short revision name. This branch fires when the embedded rev is a string that starts with info.Short — i.e. the pseudo-version carries a longer-than-canonical hash. Canonical short names are what `git rev-parse --short` yields; embedding extra hex digits makes the spelling non-canonical and wastes cache keys, so it is rejected.","triggerScenarios":"A pseudo-version was constructed by hand or by an older/different tool using a full 40-char (or non-default-length) hash while the VCS reports a shorter short-name. Also when a repo's core.abbrev setting changes the default short-hash length after a pseudo-version was recorded.","commonSituations":"Copy-pasting a full commit hash into a go.mod; switching git's `core.abbrev` from default to a larger value; pseudo-versions generated by tooling that predates the canonical-short enforcement.","solutions":["Regenerate the pseudo-version with the current toolchain: `go get <module>@<full-hash>` then copy the version string the tool writes into go.mod.","Ensure the local/CI git uses the default short-hash abbreviation when deriving versions.","If you must hand-build, extract the short hash via `git rev-parse --short <commit>` and embed exactly that."],"exampleFix":"// before (40-char hash embedded)\nrequire example.com/m v0.0.0-20240101120000-e3702bed3d42e03e85e3a1e6b1a5a3d2\n\n// after (canonical 12-char short hash)\nrequire example.com/m v0.0.0-20240101120000-e3702bed3d42","handlingStrategy":"validation","validationCode":"// Validate a pseudo-version's rev field matches the VCS short hash.\n// bash:\n//   short=$(git rev-parse --short <commit>)\n//   # ensure the pseudo-version embeds exactly $short\n//\n// Go:\npackage main\nimport (\"fmt\"; \"golang.org/x/mod/module\")\nfunc check(pseudo string) error {\n    rev, err := module.PseudoVersionRev(pseudo)\n    if err != nil { return err }\n    // compare rev against `git rev-parse --short` of the intended commit\n    fmt.Println(\"embedded rev:\", rev)\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never hand-write the hash portion of a pseudo-version; let `go get @<commit>` produce it.","Keep git's `core.abbrev` at the default so short hashes stay canonical.","When upgrading toolchains, re-derive old pseudo-versions if the default abbrev changed."],"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"}