golang/go · error
invalid quoted string in //go:embed: %s
Error message
invalid quoted string in //go:embed: %s
What it means
Returned by the //go:embed pattern parser when a backtick-quoted pattern is opened but never closed. The parser finds the opening backtick, searches args[1:] for a matching backtick, and if none is found treats the rest of the line as an invalid quoted string.
Source
Thrown at src/cmd/compile/internal/noder/noder.go:412
for args = strings.TrimSpace(args); args != ""; args = strings.TrimSpace(args) {
var path string
Switch:
switch args[0] {
default:
i := len(args)
for j, c := range args {
if unicode.IsSpace(c) {
i = j
break
}
}
path = args[:i]
args = args[i:]
case '`':
i := strings.Index(args[1:], "`")
if i < 0 {
return nil, fmt.Errorf("invalid quoted string in //go:embed: %s", args)
}
path = args[1 : 1+i]
args = args[1+i+1:]
case '"':
i := 1
for ; i < len(args); i++ {
if args[i] == '\\' {
i++
continue
}
if args[i] == '"' {
q, err := strconv.Unquote(args[:i+1])
if err != nil {
return nil, fmt.Errorf("invalid quoted string in //go:embed: %s", args[:i+1])
}
path = q
args = args[i+1:]View on GitHub (pinned to b6b368adc5)
Solutions
- Add the closing backtick to the pattern: //go:embed `pattern`.
- Prefer unquoted patterns (//go:embed pattern) unless the path contains spaces, in which case use backtick-quoted segments and close both ends.
- Run gofmt which will surface the malformed directive at edit time.
Example fix
// before //go:embed `assets/*.html // after //go:embed `assets/*.html`
Defensive patterns
Strategy: validation
Validate before calling
// Validate backtick-quoted //go:embed patterns before compiling.
for _, p := range strings.Split(line, "`") {
_ = p
}
if open := strings.Count(rest, "`"); open%2 != 0 {
return fmt.Errorf("unbalanced backticks in //go:embed")
} Prevention
- Always close backtick-quoted embed patterns.
- Prefer unquoted patterns; quote only when a path contains spaces.
- Run gofmt/gopls which flag malformed //go:embed directives.
When it happens
Trigger: A //go:embed directive contains a backtick-quoted pattern with no closing backtick, e.g. //go:embed `pattern. The strings.Index for the closing backtick returns -1 (i<0) and the error reports the entire remaining args.
Common situations: Hand-editing //go:embed directives and forgetting the closing backtick; copy-paste truncating the line; an editor autocompleting only the opening backtick.
Related errors
- go:embed requires go1.16 or later (-lang was set to %s; chec
- not a regular file
- file changed between reads
- file too large (%d bytes > %d bytes)
- go:embed requires import "embed" (or import _ "embed", if pa
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/f7e019ffc3325630.
Report an issue: GitHub.