{"record":{"id":"6271880402cc0dd6","repo":"projectdiscovery/nuclei","slug":"w-for-given-input","errorCode":null,"errorMessage":"%w for given input","messagePattern":"%w for given input","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/protocols/common/automaticscan/util.go","lineNumber":33,"sourceCode":"// by default it returns default template directory\nfunc getTemplateDirs(opts Options) ([]string, error) {\n\tdefaultTemplatesDirectories := []string{config.DefaultConfig.GetTemplateDir()}\n\t// adding custom template path if available\n\tif len(opts.ExecuterOpts.Options.Templates) > 0 {\n\t\tdefaultTemplatesDirectories = append(defaultTemplatesDirectories, opts.ExecuterOpts.Options.Templates...)\n\t}\n\t// Collect path for default directories we want to look for templates in\n\tvar allTemplates []string\n\tfor _, directory := range defaultTemplatesDirectories {\n\t\ttemplates, err := opts.ExecuterOpts.Catalog.GetTemplatePath(directory)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"could not get templates in directory\")\n\t\t}\n\t\tallTemplates = append(allTemplates, templates...)\n\t}\n\tallTemplates = sliceutil.Dedupe(allTemplates)\n\tif len(allTemplates) == 0 {\n\t\treturn nil, fmt.Errorf(\"%w for given input\", disk.ErrNoTemplatesFound)\n\t}\n\treturn allTemplates, nil\n}\n\n// LoadTemplatesWithTags loads and returns templates with given tags\nfunc LoadTemplatesWithTags(opts Options, templateDirs []string, tags []string, logInfo bool) ([]*templates.Template, error) {\n\tfinalTemplates, err := opts.Store.LoadTemplatesWithTags(templateDirs, tags)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"could not load templates\")\n\t}\n\tif len(finalTemplates) == 0 {\n\t\treturn nil, errors.New(\"could not find any templates with tech tag\")\n\t}\n\n\tif !opts.ExecuterOpts.Options.DisableClustering {\n\t\t// cluster and reduce requests\n\t\ttotalReqBeforeCluster := getRequestCount(finalTemplates) * int(opts.Target.Count())\n\t\tfinalTemplates, clusterCount, _ := templates.ClusterTemplates(finalTemplates, opts.ExecuterOpts)","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/projectdiscovery/nuclei/blob/265b3a3dec374741614e342f813c10f8b38d2bb7/pkg/protocols/common/automaticscan/util.go#L15-L51","documentation":"Runtime error from automaticscan's getTemplateDirs (pkg/protocols/common/automaticscan/util.go:33). In `-automatic-scan` mode, nuclei collects templates from the default template directory plus any -t paths via Catalog.GetTemplatePath; after dedupe, an empty result wraps disk.ErrNoTemplatesFound as \"... for given input\", surfacing the sentinel's text (typically \"no templates found\") to the caller.","triggerScenarios":"Running `-automatic-scan` when the nuclei-templates directory is absent/empty (never run `-update-templates`, custom config dir misconfigured) AND no -t targets resolve to template files, or when every candidate path errors upstream (each GetTemplatePath failure would instead surface 'could not get templates in directory').","commonSituations":"First run on a fresh install without downloading templates; NUCLEI_TEMPLATES_DIR / -config pointing at an empty folder; container/CI images that ship nuclei without the template checkout; custom template dir mounted read-only at the wrong path.","solutions":["Run `nuclei -update-templates` (or `-ut`) to populate the default template directory","Point -t / templates config at a directory that verifiably contains .yaml templates: `ls <dir>/**/*.yaml`","Fix the config: check `config.DefaultConfig.GetTemplateDir()` resolution ( -config, NUCLEI_TEMPLATES_DIR env) so it targets the real checkout","In SDK code, pre-check the directory is non-empty before enabling automatic scan and fail with your own actionable message"],"exampleFix":"# before\nnuclei -automatic-scan -target https://example.com\n# after\nnuclei -update-templates && nuclei -automatic-scan -target https://example.com","handlingStrategy":"validation","validationCode":"import fd \"github.com/projectdiscovery/utils/file\"\n\nfunc readyForAutomaticScan(templateDir string) error {\n\tif !fd.FolderExists(templateDir) {\n\t\treturn fmt.Errorf(\"template dir %s missing: run nuclei -update-templates\", templateDir)\n\t}\n\tif n := countYamlFiles(templateDir); n == 0 {\n\t\treturn fmt.Errorf(\"template dir %s empty: run nuclei -update-templates\", templateDir)\n\t}\n\treturn nil\n}","typeGuard":"func templatesPresent(dir string) bool { return fd.FolderExists(dir) && countYamlFiles(dir) > 0 }","tryCatchPattern":"if err := autoScanOpts.Init(); err != nil {\n\tif errors.Is(err, disk.ErrNoTemplatesFound) {\n\t\t// actionable: populate templates, then retry; not a bug — an env problem\n\t}\n}","preventionTips":["Install/update templates as a provisioning step before -automatic-scan runs","Verify the templates dir (config.DefaultConfig.GetTemplateDir()) in deployment scripts","CI images: bake the nuclei-templates checkout into the image","Check errors.Is(err, disk.ErrNoTemplatesFound) to branch on this sentinel"],"tags":["runner","automatic-scan","templates","setup","runtime"],"backgroundTag":null,"analyzedSha":"265b3a3dec374741614e342f813c10f8b38d2bb7","analyzedAt":"2026-08-15T20:05:51.855Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}