{"record":{"id":"522b5fb61ca074d4","repo":"googleapis/mcp-toolbox","slug":"error-finding-yml-files-in-q-w","errorCode":null,"errorMessage":"error finding YML files in %q: %w","messagePattern":"error finding YML files in %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/internal/config.go","lineNumber":556,"sourceCode":"\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to access config folder at %q: %w\", folderPath, err)\n\t}\n\tif !info.IsDir() {\n\t\treturn nil, fmt.Errorf(\"path %q is not a directory\", folderPath)\n\t}\n\n\t// Find all YAML files in the directory\n\tpattern := filepath.Join(folderPath, \"*.yaml\")\n\tyamlFiles, err := filepath.Glob(pattern)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error finding YAML files in %q: %w\", folderPath, err)\n\t}\n\n\t// Also find .yml files\n\tymlPattern := filepath.Join(folderPath, \"*.yml\")\n\tymlFiles, err := filepath.Glob(ymlPattern)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error finding YML files in %q: %w\", folderPath, err)\n\t}\n\n\t// Combine both file lists\n\tallFiles := append(yamlFiles, ymlFiles...)\n\treturn allFiles, nil\n}\n","sourceCodeStart":538,"sourceCodeEnd":563,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/cmd/internal/config.go#L538-L563","documentation":"After globbing *.yaml, GetPathsFromConfigFolder separately globs *.yml files and wraps any Glob error the same way. As with the .yaml pass, filepath.Glob only errors on a malformed pattern, so this signals the folder path produced an invalid glob pattern, not an empty directory.","triggerScenarios":"GetPathsFromConfigFolder called with a folderPath such that filepath.Glob(filepath.Join(folderPath, \"*.yml\")) returns ErrBadPattern — e.g. path containing an unterminated '[' or trailing backslash escape on Windows.","commonSituations":"Config directory names containing brackets or wildcard characters (common in CI artifact paths like 'build[1]'), or misconfigured flag/env values that embed a partial glob into the directory path.","solutions":["Escape or remove glob metacharacters in the config folder path (filepath.EvalSymlinks/Escape, rename the directory)","Confirm the --prebuilt/--tools-file value points to a plain directory, since the code appends \"*.yml\" itself","Test the pattern with filepath.Match in isolation to reproduce ErrBadPattern","Fall back to os.ReadDir + suffix filtering if directory names contain metacharacters"],"exampleFix":"// before\npaths, err := GetPathsFromConfigFolder(ctx, \"/etc/toolbox/run[2]\")\n// after\nclean := filepath.Escape(\"/etc/toolbox/run[2]\")\npaths, err := GetPathsFromConfigFolder(ctx, clean)","handlingStrategy":"validation","validationCode":"if badGlobPattern(filepath.Join(folderPath, \"*.yml\")) {\n    return fmt.Errorf(\"invalid path %q for yml glob\", folderPath)\n}\npaths, err := GetPathsFromConfigFolder(ctx, folderPath)","typeGuard":"func globPatternValid(pattern string) bool {\n    _, err := filepath.Match(pattern, \"probe\")\n    return !errors.Is(err, filepath.ErrBadPattern)\n}","tryCatchPattern":null,"preventionTips":["Avoid brackets/brackets-and-wildcards in config folder names (e.g. CI dirs like build[1])","Escape the path with filepath.Escape before passing it in","Prefer os.ReadDir-style enumeration if directory names may contain metacharacters"],"tags":["go","filesystem","glob","config-loading"],"backgroundTag":"invalid-glob-pattern","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}