{"record":{"id":"d57e922bac486530","repo":"crowdsecurity/crowdsec","slug":"errnucleirunfail","errorCode":"ErrNucleiRunFail","errorMessage":"nuclei run failed","messagePattern":"nuclei run failed","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/nucleirunner.go","lineNumber":23,"sourceCode":"\t\"context\"\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\t\"os/exec\"\n\t\"time\"\n\n\tlog \"github.com/sirupsen/logrus\"\n)\n\ntype NucleiConfig struct {\n\tPath           string   `yaml:\"nuclei_path\"`\n\tOutputDir      string   `yaml:\"output_dir\"`\n\tCmdLineOptions []string `yaml:\"cmdline_options\"`\n}\n\nvar (\n\tErrNucleiTemplateFail = errors.New(\"nuclei template failed\")\n\tErrNucleiRunFail = errors.New(\"nuclei run failed\")\n)\n\nfunc (nc *NucleiConfig) RunNucleiTemplate(ctx context.Context, testName string, templatePath string, target string) error {\n\ttstamp := time.Now().Unix()\n\n\toutputPrefix := fmt.Sprintf(\"%s/%s-%d\", nc.OutputDir, testName, tstamp)\n\t// CVE-2023-34362_CVE-2023-34362-1702562399_stderr.txt\n\targs := []string{\n\t\t// removing the banner with --silent also removes useful [WRN] lines, so it is what it is\n\t\t// \"-silent\",\n\t\t\"-u\", target,\n\t\t\"-t\", templatePath,\n\t\t\"-o\", outputPrefix + \".json\",\n\t}\n\targs = append(args, nc.CmdLineOptions...)\n\tcmd := exec.CommandContext(ctx, nc.Path, args...)\n\n\tlog.Debugf(\"Running Nuclei command: '%s'\", cmd.String())","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/nucleirunner.go#L5-L41","documentation":"This sentinel error is returned by NucleiConfig.RunNucleiTemplate/RunWithNucleiTemplate when the spawned `nuclei` command exits with a non-zero status. It wraps the underlying command error (fmt.Errorf with %w), so callers can test with errors.Is(err, ErrNucleiRunFail) to distinguish a nuclei execution failure from config or template-load problems.","triggerScenarios":"Calling RunNucleiTemplate (e.g. from hubtest's RunWithLogFile via hubtest_item.go:414) when the external nuclei binary returns a non-zero exit code: malformed cmdline_options, unreachable target host, invalid/unsupported template file, or missing/broken nuclei installation.","commonSituations":"Running crowdsec hubtest against a scenario whose nuclei template is stale or incompatible with the installed nuclei version; CI runners without network access to the target; typos in template path or YAML cmdline_options entries.","solutions":["Run the nuclei command manually with the same template and target printed by hubtest to see the real stderr wrapped in this error","Verify the template file exists and is valid YAML compatible with your nuclei version (nuclei -t <template> -target <host>)","Check that the hubtest item's cmd line_options entries are valid nuclei flags","Confirm the nuclei binary is installed, on PATH, and a version compatible with the template","Re-run with a reachable target host (NucleiTargetHost) to rule out network/timeout issues"],"exampleFix":"// before: opaque failure at the call site\nerr = nucleiConfig.RunNucleiTemplate(ctx, t.Name, nucleiTemplate, t.NucleiTargetHost)\n// after: inspect the wrapped cause\nif err != nil {\n    if errors.Is(err, ErrNucleiRunFail) {\n        log.Fatalf(\"nuclei execution failed: %v\", err) // %v prints the underlying cmd error\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"// pre-check before running\nif _, err := exec.LookPath(\"nuclei\"); err != nil { return fmt.Errorf(\"nuclei not installed: %w\", err) }\nif _, err := os.Stat(templatePath); err != nil { return fmt.Errorf(\"template missing: %w\", err) }","typeGuard":"func isNucleiRunFail(err error) bool { return errors.Is(err, ErrNucleiRunFail) }","tryCatchPattern":"if err := nucleiConfig.RunNucleiTemplate(ctx, name, tpl, target); err != nil {\n    if errors.Is(err, ErrNucleiRunFail) {\n        log.Printf(\"nuclei failed: %v\", err) // wrapped cmdErr follows the sentinel\n    }\n    return err\n}","preventionTips":["Pin and test the nuclei version used by hubtest","Run `nuclei -t <template> -target <host>` manually in CI before hubtest","Validate template YAML and cmdline_options entries when authoring hub tests","Ensure CI has network reachability to the nuclei target host"],"tags":["nuclei","hubtest","external-command","testing"],"backgroundTag":"http-request-failed","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}