{"record":{"id":"e92c7b6d08624aa3","repo":"crowdsecurity/crowdsec","slug":"w-v","errorCode":null,"errorMessage":"%w: %v","messagePattern":"%w: %v","errorType":"exception","errorClass":"ErrNucleiRunFail","httpStatus":null,"severity":"error","filePath":"pkg/hubtest/nucleirunner.go","lineNumber":71,"sourceCode":"\t\tlog.Errorf(\"Error writing stdout: %s\", err)\n\t}\n\n\terrBytes := outErr.Bytes()\n\n\tif err := os.WriteFile(outputPrefix+\"_stderr.txt\", errBytes, 0o644); err != nil {\n\t\tlog.Errorf(\"Error writing stderr: %s\", err)\n\t}\n\n\tif cmdErr != nil {\n\t\t// display stderr in addition to writing to a file\n\t\tos.Stdout.Write(errBytes)\n\t\tos.Stdout.WriteString(\"\\n\")\n\n\t\tfmt.Fprintln(os.Stdout, \"Stdout saved to\", outputPrefix+\"_stdout.txt\")\n\t\tfmt.Fprintln(os.Stdout, \"Stderr saved to\", outputPrefix+\"_stderr.txt\")\n\t\tfmt.Fprintln(os.Stdout, \"Nuclei generated output saved to\", outputPrefix+\".json\")\n\n\t\treturn fmt.Errorf(\"%w: %v\", ErrNucleiRunFail, cmdErr)\n\t}\n\n\tif out.String() == \"\" {\n\t\tfmt.Fprintln(os.Stdout, \"Stdout saved to\", outputPrefix+\"_stdout.txt\")\n\t\tfmt.Fprintln(os.Stdout, \"Stderr saved to\", outputPrefix+\"_stderr.txt\")\n\t\tfmt.Fprintln(os.Stdout, \"Nuclei generated output saved to\", outputPrefix+\".json\")\n\n\t\t// No stdout means no finding, it means our test failed\n\t\treturn ErrNucleiTemplateFail\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":53,"sourceCodeEnd":85,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/nucleirunner.go#L53-L85","documentation":"RunNucleiTemplate executes the nuclei binary against a template and, when the underlying command exits with an error, wraps the sentinel ErrNucleiRunFail with the command's error output. It tells the hubtest user that the nuclei scan itself failed (bad binary, bad template, bad target), not that assertion logic failed. Check the saved _stdout.txt/_stderr.txt files printed just before the error for the real cause.","triggerScenarios":"Calling RunWithNucleiTemplate/RunNucleiTemplate with a template whose nuclei invocation exits non-zero: nuclei not installed or wrong PATH, malformed template YAML, unreachable target URL, or invalid nuclei flags.","commonSituations":"CI runner without nuclei in PATH; template referencing an outdated nuclei syntax after a nuclei upgrade; target service not running during test; output prefix directory not writable.","solutions":["Run `nuclei -version` (or run the nuclei command manually with the same args) to confirm the binary works and inspect the stderr file saved next to the output prefix.","Install/upgrade nuclei and ensure it is on PATH for the test process.","Validate the template with `nuclei -t <template> -validate` and fix syntax/deprecated fields.","Confirm the target URL/service in the test config is reachable before running hubtest."],"exampleFix":"// before (no check)\nerr := hubtest.RunWithNucleiTemplate(ctx, tpl, target)\n// after\nif _, err := exec.LookPath(\"nuclei\"); err != nil {\n\treturn fmt.Errorf(\"nuclei binary not found in PATH: %w\", err)\n}\nif err := hubtest.RunWithNucleiTemplate(ctx, tpl, target); err != nil {\n\tif !errors.Is(err, hubtest.ErrNucleiRunFail) {\n\t\treturn err\n\t}\n\tlog.Printf(\"nuclei run failed, see *_stderr.txt: %v\", err)\n}","handlingStrategy":"try-catch","validationCode":"if _, err := exec.LookPath(\"nuclei\"); err != nil {\n\treturn fmt.Errorf(\"nuclei not installed/on PATH: %w\", err)\n}\nif err := os.MkdirAll(filepath.Dir(outputPrefix), 0o755); err != nil {\n\treturn err\n}","typeGuard":null,"tryCatchPattern":"err := hubtest.RunWithNucleiTemplate(ctx, tpl, target)\nif errors.Is(err, hubtest.ErrNucleiRunFail) {\n\t// inspect outputPrefix+\"_stderr.txt\" for the nuclei-level cause\n\tlog.Printf(\"nuclei run failed: %v\", err)\n\treturn err\n}\nif err != nil {\n\treturn err\n}","preventionTips":["Install nuclei and pin its version in CI images.","Validate templates with `nuclei -t <tpl> -validate` before hubtest.","Read the saved _stdout.txt/_stderr.txt whenever ErrNucleiRunFail appears.","Ensure the target service is up before running nuclei-based tests."],"tags":["hubtest","nuclei","command-execution","external-binary"],"backgroundTag":"command-not-found","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"}