projectdiscovery/nuclei · error

%w for given input

Error message

%w for given input

What it means

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.

Source

Thrown at pkg/protocols/common/automaticscan/util.go:33

// by default it returns default template directory
func getTemplateDirs(opts Options) ([]string, error) {
	defaultTemplatesDirectories := []string{config.DefaultConfig.GetTemplateDir()}
	// adding custom template path if available
	if len(opts.ExecuterOpts.Options.Templates) > 0 {
		defaultTemplatesDirectories = append(defaultTemplatesDirectories, opts.ExecuterOpts.Options.Templates...)
	}
	// Collect path for default directories we want to look for templates in
	var allTemplates []string
	for _, directory := range defaultTemplatesDirectories {
		templates, err := opts.ExecuterOpts.Catalog.GetTemplatePath(directory)
		if err != nil {
			return nil, errors.Wrap(err, "could not get templates in directory")
		}
		allTemplates = append(allTemplates, templates...)
	}
	allTemplates = sliceutil.Dedupe(allTemplates)
	if len(allTemplates) == 0 {
		return nil, fmt.Errorf("%w for given input", disk.ErrNoTemplatesFound)
	}
	return allTemplates, nil
}

// LoadTemplatesWithTags loads and returns templates with given tags
func LoadTemplatesWithTags(opts Options, templateDirs []string, tags []string, logInfo bool) ([]*templates.Template, error) {
	finalTemplates, err := opts.Store.LoadTemplatesWithTags(templateDirs, tags)
	if err != nil {
		return nil, errors.Wrap(err, "could not load templates")
	}
	if len(finalTemplates) == 0 {
		return nil, errors.New("could not find any templates with tech tag")
	}

	if !opts.ExecuterOpts.Options.DisableClustering {
		// cluster and reduce requests
		totalReqBeforeCluster := getRequestCount(finalTemplates) * int(opts.Target.Count())
		finalTemplates, clusterCount, _ := templates.ClusterTemplates(finalTemplates, opts.ExecuterOpts)

View on GitHub (pinned to 265b3a3dec)

Solutions

  1. Run `nuclei -update-templates` (or `-ut`) to populate the default template directory
  2. Point -t / templates config at a directory that verifiably contains .yaml templates: `ls <dir>/**/*.yaml`
  3. Fix the config: check `config.DefaultConfig.GetTemplateDir()` resolution ( -config, NUCLEI_TEMPLATES_DIR env) so it targets the real checkout
  4. In SDK code, pre-check the directory is non-empty before enabling automatic scan and fail with your own actionable message

Example fix

# before
nuclei -automatic-scan -target https://example.com
# after
nuclei -update-templates && nuclei -automatic-scan -target https://example.com
Defensive patterns

Strategy: validation

Validate before calling

import fd "github.com/projectdiscovery/utils/file"

func readyForAutomaticScan(templateDir string) error {
	if !fd.FolderExists(templateDir) {
		return fmt.Errorf("template dir %s missing: run nuclei -update-templates", templateDir)
	}
	if n := countYamlFiles(templateDir); n == 0 {
		return fmt.Errorf("template dir %s empty: run nuclei -update-templates", templateDir)
	}
	return nil
}

Type guard

func templatesPresent(dir string) bool { return fd.FolderExists(dir) && countYamlFiles(dir) > 0 }

Try / catch

if err := autoScanOpts.Init(); err != nil {
	if errors.Is(err, disk.ErrNoTemplatesFound) {
		// actionable: populate templates, then retry; not a bug — an env problem
	}
}

Prevention

When it happens

Trigger: 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').

Common situations: 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.

Related errors


AI-assisted analysis of projectdiscovery/nuclei@265b3a3dec (2026-08-15). Data as JSON: /api/errors/6271880402cc0dd6. Report an issue: GitHub.