{"record":{"id":"641aa477f8e1b81f","repo":"golang/go","slug":"syntax-error-641aa4","errorCode":null,"errorMessage":"syntax error","messagePattern":"syntax error","errorType":"exception","errorClass":"module.InvalidVersionError","httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modfetch/coderepo.go","lineNumber":823,"sourceCode":"\t\t}\n\t\tif semver.Build(rev) == \"+incompatible\" {\n\t\t\trev = rev[:len(rev)-len(\"+incompatible\")]\n\t\t}\n\t\tif r.codeDir == \"\" {\n\t\t\treturn rev\n\t\t}\n\t\treturn r.codeDir + \"/\" + rev\n\t}\n\treturn rev\n}\n\nfunc (r *codeRepo) versionToRev(version string) (rev string, err error) {\n\tif !semver.IsValid(version) {\n\t\treturn \"\", &module.ModuleError{\n\t\t\tPath: r.modPath,\n\t\t\tErr: &module.InvalidVersionError{\n\t\t\t\tVersion: version,\n\t\t\t\tErr:     errors.New(\"syntax error\"),\n\t\t\t},\n\t\t}\n\t}\n\treturn r.revToRev(version), nil\n}\n\n// findDir locates the directory within the repo containing the module.\n//\n// If r.pathMajor is non-empty, this can be either r.codeDir or — if a go.mod\n// file exists — r.codeDir/r.pathMajor[1:].\nfunc (r *codeRepo) findDir(ctx context.Context, version string) (rev, dir string, gomod []byte, err error) {\n\trev, err = r.versionToRev(version)\n\tif err != nil {\n\t\treturn \"\", \"\", nil, err\n\t}\n\n\t// Load info about go.mod but delay consideration\n\t// (except I/O error) until we rule out v2/go.mod.","sourceCodeStart":805,"sourceCodeEnd":841,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modfetch/coderepo.go#L805-L841","documentation":"versionToRev converts a requested semantic version into a VCS revision. If semver.IsValid(version) is false, it returns a module.InvalidVersionError wrapping \"syntax error\", signaling the version string is not well-formed semantic versioning. Callers see this as an invalid version for the module.","triggerScenarios":"Passing a non-semver version string such as \"1.2\", \"v1\", \"latest-stable\", or a tag with disallowed characters to versionToRev (e.g. via `go get module@<bad-version>`).","commonSituations":"Typos in `go get foo@version`; tags used without the required `v` prefix; mixing VCS tag names with module version syntax; forgetting the patch component (v1.2 instead of v1.2.0).","solutions":["Use a fully valid semver version such as `v1.2.3` (include the leading v and three numeric components).","For a non-tagged commit, use a canonical pseudo-version or a raw commit hash instead of a malformed semver.","Double-check the v prefix and component count against the module's published tags."],"exampleFix":"// before\n//   go get example.com/foo@1.2      // syntax error\n// after\n//   go get example.com/foo@v1.2.0","handlingStrategy":"validation","validationCode":"// Validate a version before passing it to the go command:\n//   import \"golang.org/x/mod/semver\"\n//   if !semver.IsValid(version) { /* reject or canonicalize */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use canonical semver (vMAJOR.MINOR.PATCH) for module versions.","Use commit hashes or pseudo-versions for non-tagged revisions instead of inventing version strings."],"tags":["go","modules","semver","versioning"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}