projectdiscovery/nuclei · error

could not write go template: %v

Error message

could not write go template: %v

What it means

TemplateData.WriteGoTemplate failed while writing generated bindings into generatedDir/go/lib<module>. Causes: cannot create the output directory (permissions, read-only checkout), file write errors, or template execution hitting an AST/type shape the generator does not handle.

Source

Thrown at pkg/js/devtools/bindgen/cmd/bindgen/main.go:63

	}
	for _, module := range modules {
		log.Printf("[module] Generating %s", module)

		data, err := generator.CreateTemplateData(filepath.Join(dir, module), "github.com/projectdiscovery/nuclei/v3/pkg/js/libs/")
		if err != nil {
			return fmt.Errorf("could not create template data: %v", err)
		}

		prefixed := "lib" + module
		// if !goOnly {
		// 	err = data.WriteJSTemplate(filepath.Join(generatedDir, "js/"+prefixed), module)
		// 	if err != nil {
		// 		return fmt.Errorf("could not write js template: %v", err)
		// 	}
		// }
		err = data.WriteGoTemplate(path.Join(generatedDir, "go/"+prefixed), module)
		if err != nil {
			return fmt.Errorf("could not write go template: %v", err)
		}
		// disabled for now since we have static website for docs
		// err = data.WriteMarkdownLibraryDocumentation(path.Join(generatedDir, "markdown/"), module)
		// if err != nil {
		// 	return fmt.Errorf("could not write markdown template: %v", err)
		// }

		// err = data.WriteMarkdownIndexTemplate(path.Join(generatedDir, "markdown/"))
		// if err != nil {
		// 	return fmt.Errorf("could not write markdown index template: %v", err)
		// }
		data.InitNativeScripts()
	}
	return nil
}

View on GitHub (pinned to 265b3a3dec)

Solutions

  1. Check write permission on pkg/js/generated and fix ownership of stale files (sudo chown -R $USER pkg/js/generated)
  2. Clean the target dir (git clean -xfd pkg/js/generated) and regenerate via make devtools-all
  3. If it persists on a specific module's types, minimize the offending declaration and report it against the devtool

Example fix

# before
./bindgen ./pkg/js/libs/smb   # fails writing generated output

# after
git clean -xfd pkg/js/generated && make devtools-all
Defensive patterns

Strategy: try-catch

Validate before calling

if err := os.MkdirAll(filepath.Join(generatedDir, "go"), 0o755); err != nil {
    log.Fatalf("output dir not writable: %v", err)
}

Try / catch

On WriteGoTemplate failure, surface the wrapped error, fix permissions/staleness of pkg/js/generated, clean it (git clean -xfd pkg/js/generated), and re-run the make target once.

Prevention

When it happens

Trigger: bindgen successfully parsed the module but failed emitting pkg/js/generated/go/lib<module>/*.go — unwritable path, disk full, or a generator bug on exotic type declarations.

Common situations: Running codegen in a read-only clone or as a user without write access; a stale generated dir with root-owned files from an earlier sudo run; newly added struct shapes (generics, embedded aliases) the emitter chokes on.

Related errors


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