golang/go · error
no matching files found
Error message
no matching files found
What it means
After processing a single pattern (end of the per-pattern loop body at line 2304), if the accumulated `list` is empty the pattern matched nothing at all — no file, no directory, nothing. This is distinct from 889 (a directory matched but was empty): here the glob itself produced no usable match. It is an error rather than a silent skip so that misspelled embed patterns are caught at build time.
Source
Thrown at src/cmd/go/internal/load/pkg.go:2305
}
count++
if have[rel] != pid {
have[rel] = pid
list = append(list, rel)
}
return nil
})
if err != nil {
return nil, nil, err
}
if count == 0 {
return nil, nil, fmt.Errorf("cannot embed directory %s: contains no embeddable files", rel)
}
}
}
if len(list) == 0 {
return nil, nil, fmt.Errorf("no matching files found")
}
sort.Strings(list)
pmap[pattern] = list
}
for file := range have {
files = append(files, file)
}
sort.Strings(files)
return files, pmap, nil
}
func validEmbedPattern(pattern string) bool {
return pattern != "." && fs.ValidPath(pattern)
}
// isBadEmbedName reports whether name is the base name of a file that
// can't or won't be included in modules and therefore shouldn't be treatedView on GitHub (pinned to b6b368adc5)
Solutions
- Verify the path in the //go:embed directive exists relative to the .go file's package directory.
- Check git tracking: `git ls-files <pattern>` — if empty, the files are not in the repo.
- Fix typos and case; embed patterns are case-sensitive on all platforms.
Example fix
// before: //go:embed statik // after: //go:embed static
Defensive patterns
Strategy: validation
Validate before calling
// Verify an embed pattern resolves to at least one match before building.
package embedcheck
import (
"errors"
"os"
"path/filepath"
)
func EmbedPatternMatches(pkgDir, pattern string) error {
matches, err := filepath.Glob(filepath.Join(pkgDir, pattern))
if err != nil {
return errors.New("bad embed pattern: " + err.Error())
}
if len(matches) == 0 {
return errors.New("embed pattern matched nothing: " + pattern)
}
return nil
} Prevention
- Always `git ls-files <pattern>` after writing a //go:embed line — if it is empty in git, it will be empty in CI.
- Treat embed patterns as case-sensitive on all platforms.
When it happens
Trigger: //go:embed of a path that does not exist under the package directory, or that only matches hidden/badly-named files at the top level (no directory descent). E.g. `//go:embed typo.txt`.
Common situations: Typo in the pattern; assets not yet checked in; CI building from a shallow checkout that omits the assets; case mismatch in the pattern.
Related errors
- invalid pattern syntax
- cannot embed %s %s: in different module
- cannot embed %s %s: in non-directory %s
- cannot embed %s %s: invalid name %s
- cannot embed %s %s: in invalid directory %s
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/8cd252602a1fbd8a.
Report an issue: GitHub.