{"record":{"id":"f9ea2b9ef9e1ca3a","repo":"golang/go","slug":"import-path-contains-invalid-utf-8-sequence-q","errorCode":null,"errorMessage":"import path contains invalid UTF-8 sequence: %q","messagePattern":"import path contains invalid UTF-8 sequence: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/compile/internal/noder/import.go","lineNumber":320,"sourceCode":"func checkImportPath(path string, allowSpace bool) error {\n\tif path == \"\" {\n\t\treturn errors.New(\"import path is empty\")\n\t}\n\n\tif strings.Contains(path, \"\\x00\") {\n\t\treturn errors.New(\"import path contains NUL\")\n\t}\n\n\tfor ri := range base.ReservedImports {\n\t\tif path == ri {\n\t\t\treturn fmt.Errorf(\"import path %q is reserved and cannot be used\", path)\n\t\t}\n\t}\n\n\tfor _, r := range path {\n\t\tswitch {\n\t\tcase r == utf8.RuneError:\n\t\t\treturn fmt.Errorf(\"import path contains invalid UTF-8 sequence: %q\", path)\n\t\tcase r < 0x20 || r == 0x7f:\n\t\t\treturn fmt.Errorf(\"import path contains control character: %q\", path)\n\t\tcase r == '\\\\':\n\t\t\treturn fmt.Errorf(\"import path contains backslash; use slash: %q\", path)\n\t\tcase !allowSpace && unicode.IsSpace(r):\n\t\t\treturn fmt.Errorf(\"import path contains space character: %q\", path)\n\t\tcase strings.ContainsRune(\"!\\\"#$%&'()*,:;<=>?[]^`{|}\", r):\n\t\t\treturn fmt.Errorf(\"import path contains invalid character '%c': %q\", r, path)\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":302,"sourceCodeEnd":334,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/compile/internal/noder/import.go#L302-L334","documentation":"Returned by checkImportPath when iterating the path's runes encounters utf8.RuneError, which signals invalid UTF-8 (either a lone continuation byte or an overlong/invalid sequence). Go import paths must be valid UTF-8.","triggerScenarios":"An import path string contains bytes that do not decode as valid UTF-8; the for-range loop yields utf8.RuneError and the error names the whole path.","commonSituations":"Pasting an import path with mojibake or non-UTF-8 bytes; a filesystem-derived path encoded in Latin-1 or GBK; binary corruption of a source file's import line.","solutions":["Re-encode the import path as UTF-8 (iconv or your editor's encoding setting).","Retype the import line by hand to drop stray bytes.","Validate with a UTF-8 checker (e.g. printf %s path | iconv -f utf-8 -t utf-8)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if !utf8.ValidString(path) {\n    return fmt.Errorf(\"import path is not valid UTF-8: %q\", path)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate import paths from ASCII identifiers.","Validate paths with utf8.ValidString before compiling."],"tags":["go-compiler","import-path","utf-8","validation"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}