golang/go · error
import path contains control character: %q
Error message
import path contains control character: %q
What it means
Returned by checkImportPath when a rune in the path is a C0 control character (r < 0x20) or DEL (0x7f). Import paths may not contain control characters because they are not portable across filesystems, shells, or version control.
Source
Thrown at src/cmd/compile/internal/noder/import.go:322
return errors.New("import path is empty")
}
if strings.Contains(path, "\x00") {
return errors.New("import path contains NUL")
}
for ri := range base.ReservedImports {
if path == ri {
return fmt.Errorf("import path %q is reserved and cannot be used", path)
}
}
for _, r := range path {
switch {
case r == utf8.RuneError:
return fmt.Errorf("import path contains invalid UTF-8 sequence: %q", path)
case r < 0x20 || r == 0x7f:
return fmt.Errorf("import path contains control character: %q", path)
case r == '\\':
return fmt.Errorf("import path contains backslash; use slash: %q", path)
case !allowSpace && unicode.IsSpace(r):
return fmt.Errorf("import path contains space character: %q", path)
case strings.ContainsRune("!\"#$%&'()*,:;<=>?[]^`{|}", r):
return fmt.Errorf("import path contains invalid character '%c': %q", r, path)
}
}
return nil
}
View on GitHub (pinned to b6b368adc5)
Solutions
- Inspect the import line for invisible characters (cat -A or your editor's show-whitespace).
- Retype the import path removing all control bytes.
- Generate import paths from trusted identifiers only.
Defensive patterns
Strategy: validation
Validate before calling
for _, r := range path {
if r < 0x20 || r == 0x7f {
return fmt.Errorf("control character in import path")
}
} Prevention
- Strip control bytes from generated paths.
- Show invisible characters in your editor when editing import lines.
When it happens
Trigger: An import path literal contains a tab, newline, NUL (already guarded separately), backspace, ESC, or DEL; the switch fires the r < 0x20 || r == 0x7f case.
Common situations: A multi-line import accidentally containing a literal newline/tab, terminal copy-paste inserting control bytes, or a generated import with embedded formatting characters.
Related errors
- import path %q is reserved and cannot be used
- import path contains invalid UTF-8 sequence: %q
- import path contains backslash; use slash: %q
- import path contains space character: %q
- import path contains invalid character '%c': %q
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/64bad022f1e77abc.
Report an issue: GitHub.