golang/go · error
internal error: MatchDirs: %s is not a valid filesystem patt
Error message
internal error: MatchDirs: %s is not a valid filesystem pattern
What it means
Internal error added to a Match via MatchDirs when the match's pattern is NOT a local/filesystem pattern (IsLocal() false). MatchDirs requires a pattern starting with an absolute path, './', or '../'; any other pattern reaching it indicates the dispatcher misrouted a non-local pattern to the filesystem matcher.
Source
Thrown at src/cmd/go/internal/search/search.go:289
path = "/" + path
}
if !strings.HasSuffix(path, "/") {
path += "/"
}
return path
}
// MatchDirs sets m.Dirs to a non-nil slice containing all directories that
// potentially match a local pattern. The pattern must begin with an absolute
// path, or "./", or "../". On Windows, the pattern may use slash or backslash
// separators or a mix of both.
//
// If any errors may have caused the set of directories to be incomplete,
// MatchDirs appends those errors to m.Errs.
func (m *Match) MatchDirs(modRoots []string) {
m.Dirs = []string{}
if !m.IsLocal() {
m.AddError(fmt.Errorf("internal error: MatchDirs: %s is not a valid filesystem pattern", m.pattern))
return
}
if m.IsLiteral() {
m.Dirs = []string{m.pattern}
return
}
// Clean the path and create a matching predicate.
// filepath.Clean removes "./" prefixes (and ".\" on Windows). We need to
// preserve these, since they are meaningful in MatchPattern and in
// returned import paths.
cleanPattern := filepath.Clean(m.pattern)
isLocal := strings.HasPrefix(m.pattern, "./") || (os.PathSeparator == '\\' && strings.HasPrefix(m.pattern, `.\`))
prefix := ""
if cleanPattern != "." && isLocal {
prefix = "./"
cleanPattern = "." + string(os.PathSeparator) + cleanPatternView on GitHub (pinned to b6b368adc5)
Solutions
- Route non-local patterns to MatchPackages, keeping MatchDirs for local patterns.
- Guard the dispatch with m.IsLocal() before calling MatchDirs.
- Report as a Go toolchain bug if encountered via a normal 'go' command.
Example fix
// before
m := search.NewMatch("example.com/pkg")
m.MatchDirs(modRoots) // error: internal error: MatchDirs: example.com/pkg is not a valid filesystem pattern
// after
m := search.NewMatch("example.com/pkg")
m.MatchPackages() // correct matcher for non-local patterns Defensive patterns
Strategy: type-guard
Validate before calling
// Route by pattern locality before matching:
// if m.IsLocal() { m.MatchDirs(modRoots) } else { m.MatchPackages() } Type guard
func matchCorrectly(m *search.Match, modRoots []string) {
if m.IsLocal() {
m.MatchDirs(modRoots)
} else {
m.MatchPackages()
}
} Prevention
- Always check IsLocal() before choosing MatchDirs vs MatchPackages.
- Never call MatchDirs on import-path patterns like 'all', 'std', or 'example.com/...'.
- Report CLI occurrences as a toolchain bug.
When it happens
Trigger: Calling search.Match.MatchDirs() on a Match whose pattern is an import-path pattern like 'example.com/pkg' or 'all' — the dispatcher that should have routed to MatchPackages misrouted instead.
Common situations: Only in tooling/tests that drive search.Match with the wrong matcher for a non-local pattern; not produced by standard CLI paths.
Related errors
- internal error: MatchPackages: %s is not a valid package pat
- internal error: main module version is not allowed: %w
- internal error: package %s is in the main module (%s), but v
- not in workspace mode but number of indexes is %v, not 1
- internal error: invalid binary cache entry: not a directory
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/b277c0b25bce86a0.
Report an issue: GitHub.