{"record":{"id":"5d1f505b018fd680","repo":"golang/go","slug":"invalid-character-u","errorCode":null,"errorMessage":"invalid character %#U","messagePattern":"invalid character %#U","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/compile/internal/types2/resolver.go","lineNumber":84,"sourceCode":"\t\t}\n\tcase l > r && (constDecl || r != 1): // if r == 1 it may be a multi-valued function and we can't say anything yet\n\t\tn := names[r]\n\t\tcheck.errorf(n, code, \"missing init expr for %s\", n.Value)\n\t}\n}\n\nfunc validatedImportPath(path string) (string, error) {\n\ts, err := strconv.Unquote(path)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tif s == \"\" {\n\t\treturn \"\", fmt.Errorf(\"empty string\")\n\t}\n\tconst illegalChars = `!\"#$%&'()*,:;<=>?[\\]^{|}` + \"`\\uFFFD\"\n\tfor _, r := range s {\n\t\tif !unicode.IsGraphic(r) || unicode.IsSpace(r) || strings.ContainsRune(illegalChars, r) {\n\t\t\treturn s, fmt.Errorf(\"invalid character %#U\", r)\n\t\t}\n\t}\n\treturn s, nil\n}\n\n// declarePkgObj declares obj in the package scope, records its ident -> obj mapping,\n// and updates check.objMap. The object must not be a function or method.\nfunc (check *Checker) declarePkgObj(ident *syntax.Name, obj Object, d *declInfo) {\n\tassert(ident.Value == obj.Name())\n\n\t// spec: \"A package-scope or file-scope identifier with name init\n\t// may only be declared to be a function with this (func()) signature.\"\n\tif ident.Value == \"init\" {\n\t\tcheck.error(ident, InvalidInitDecl, \"cannot declare init - must be func\")\n\t\treturn\n\t}\n\n\t// spec: \"The main package must have package name main and declare","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/compile/internal/types2/resolver.go#L66-L102","documentation":"After unquoting and checking for emptiness, validatedImportPath scans each rune of the import path against a set of illegal characters (!\"#$%&'()*,:;<=>?[\\]^{|}` plus U+FFFD) and Unicode categories (non-graphic, whitespace). If any rune matches, this error is returned with the offending character in %#U format (e.g., invalid character U+0021 '!'). The function returns the partial path (up to the error) as the first return value.","triggerScenarios":"An import path containing any character from the illegalChars set, non-graphic Unicode characters, or whitespace. Examples: import \"example.com/foo;bar\" (semicolon), import \"example.com/foo bar\" (space), import \"example.com/foo\\x00bar\" (null byte), import containing Unicode replacement character U+FFFD.","commonSituations":"Typos in import paths. Shell escaping issues that inject special characters. URL-style paths accidentally used as import paths (e.g., https://). Copy-paste from rich text that includes smart quotes or invisible characters. Module paths with unusual characters.","solutions":["Use only valid Go import path characters: letters, digits, slashes, dots, dashes, underscores, and tildes","Fix the module path in go.mod if it contains illegal characters","Check for invisible characters or smart quotes by examining the file with a hex editor or cat -A","Run gofmt on the source file — it may flag or normalize some import path issues"],"exampleFix":"// before\nimport \"example.com/foo;bar\"\n\n// after\nimport \"example.com/foo/bar\"","handlingStrategy":"validation","validationCode":"// Validate import paths contain only legal characters\nfunc validateImportPath(path string) error {\n    if path == \"\" {\n        return fmt.Errorf(\"empty import path\")\n    }\n    const illegalChars = `!\"#$%&'()*,:;<=>?[\\]^{|}` + \"`\\uFFFD\"\n    for _, r := range path {\n        if !unicode.IsGraphic(r) || unicode.IsSpace(r) || strings.ContainsRune(illegalChars, r) {\n            return fmt.Errorf(\"invalid character %#U in import path %q\", r, path)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only ASCII letters, digits, slashes, dots, dashes, and underscores in import paths","Avoid URL-style prefixes (https://, git+) in import paths — use the module path directly","Check for invisible characters in import paths when copy-pasting from documentation","Run go vet which can detect some import path issues"],"tags":["go-types","go-imports","validation","unicode"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}