projectdiscovery/nuclei · error

could not create entity parser: %s

Error message

could not create entity parser: %s

What it means

The tsgen codegen tool could not construct its entity parser for a walked directory (tsgen.NewEntityParser(dir) failed) and — being a codegen CLI — panics immediately. Root causes: directory missing/unreadable, or parser setup failing on the directory's Go files.

Source

Thrown at pkg/js/devtools/tsgen/cmd/tsgen/main.go:87

		// only load module directory skip root directory
		if d.IsDir() {
			files, _ := os.ReadDir(path)
			for _, file := range files {
				if !file.IsDir() && strings.HasSuffix(file.Name(), ".go") {
					dirs = append(dirs, path)
					break
				}
			}
		}
		return nil
	})

	// walk each directory
	for _, dir := range dirs {
		entityList := []tsgen.Entity{}
		ep, err := tsgen.NewEntityParser(dir)
		if err != nil {
			panic(fmt.Errorf("could not create entity parser: %s", err))
		}
		if err := ep.Parse(); err != nil {
			panic(fmt.Errorf("could not parse entities: %s", err))
		}
		entityList = append(entityList, ep.GetEntities()...)
		entityList = sortEntities(entityList)
		var buff bytes.Buffer
		err = tmpl.Execute(&buff, entityList)
		if err != nil {
			panic(err)
		}
		moduleName := filepath.Base(dir)
		gologger.Info().Msgf("Writing %s.ts", moduleName)
		// create appropriate directory if missing
		// _ = fileutil.CreateFolder(filepath.Join(out, moduleName))
		_ = os.WriteFile(filepath.Join(out, moduleName)+".ts", buff.Bytes(), 0755)
	}

View on GitHub (pinned to 265b3a3dec)

Solutions

  1. Run from the repository root via the make targets (make jsupdate-all / devtools-all) so directory walking matches expectations
  2. Verify each walked dir exists and is readable: ls pkg/js/libs/<module>
  3. Read the wrapped %s message — it names the underlying parser failure

Example fix

# before
tsgen ../nuclei/pkg/js/libs   # wrong cwd

# after
cd /path/to/nuclei && make jsupdate-all
Defensive patterns

Strategy: validation

Validate before calling

for _, dir := range dirs {
    info, err := os.Stat(dir)
    if err != nil || !info.IsDir() {
        log.Fatalf("cannot walk %s: %v", dir, err)
    }
}

Try / catch

The tool panics by design; run tsgen via the make targets and fix whatever the wrapped %s names (missing dir, permissions) before re-running.

Prevention

When it happens

Trigger: Running tsgen where a collected dir does not exist, lacks read permission, or has no parseable Go files, so NewEntityParser returns an error.

Common situations: Running tsgen from outside the repo root so relative dirs resolve wrongly; a moved/renamed lib dir; permission-restricted checkouts (CI sandboxes).

Related errors


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