{"record":{"id":"91fb25fe5ca64d82","repo":"golang/go","slug":"import-path-is-empty","errorCode":null,"errorMessage":"import path is empty","messagePattern":"import path is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/compile/internal/noder/import.go","lineNumber":304,"sourceCode":"// the exportdata.\nfunc addFingerprint(path string, data string) error {\n\tvar fingerprint goobj.FingerprintType\n\n\tpos := len(data) - len(fingerprint)\n\tif pos < 0 {\n\t\treturn fmt.Errorf(\"missing linker fingerprint in exportdata, but found %q\", data)\n\t}\n\tbuf := []byte(data[pos:])\n\n\tcopy(fingerprint[:], buf)\n\tbase.Ctxt.AddImport(path, fingerprint)\n\n\treturn nil\n}\n\nfunc 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)","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/compile/internal/noder/import.go#L286-L322","documentation":"Thrown by checkImportPath when the import path is the empty string. This is the first validation in checkImportPath and rejects degenerate imports before any further character-level checks run.","triggerScenarios":"Code or tooling that produces an empty import path string and passes it to the compiler/import resolver, e.g. `import \"\"` in generated or hand-edited source, or an import map keyed by \"\".","commonSituations":"Buggy code generation that emits an empty import; string formatting bug that drops the path; an import map that maps something to/from an empty key; accidental blank import of an empty string.","solutions":["Ensure the import declaration has a real, non-empty path.","Audit code generators / templating that interpolate import paths.","Check import-map configuration for empty keys or values."],"exampleFix":"// before\nimport \"\"\n// after\nimport \"fmt\"","handlingStrategy":"validation","validationCode":"// Reject empty import paths before passing them to the compiler.\nfunc nonEmptyImport(p string) bool { return p != \"\" }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate generated import paths are non-empty before writing source.","Add a lint rule that flags `import \"\"`.","Sanitize import-map keys/values to drop empty entries."],"tags":["compiler","imports","validation","empty-path"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}