crowdsecurity/crowdsec · error
ErrNucleiRunFail
ErrNucleiRunFail
Error message
nuclei run failed
What it means
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.
Source
Thrown at pkg/hubtest/nucleirunner.go:23
"context"
"errors"
"fmt"
"os"
"os/exec"
"time"
log "github.com/sirupsen/logrus"
)
type NucleiConfig struct {
Path string `yaml:"nuclei_path"`
OutputDir string `yaml:"output_dir"`
CmdLineOptions []string `yaml:"cmdline_options"`
}
var (
ErrNucleiTemplateFail = errors.New("nuclei template failed")
ErrNucleiRunFail = errors.New("nuclei run failed")
)
func (nc *NucleiConfig) RunNucleiTemplate(ctx context.Context, testName string, templatePath string, target string) error {
tstamp := time.Now().Unix()
outputPrefix := fmt.Sprintf("%s/%s-%d", nc.OutputDir, testName, tstamp)
// CVE-2023-34362_CVE-2023-34362-1702562399_stderr.txt
args := []string{
// removing the banner with --silent also removes useful [WRN] lines, so it is what it is
// "-silent",
"-u", target,
"-t", templatePath,
"-o", outputPrefix + ".json",
}
args = append(args, nc.CmdLineOptions...)
cmd := exec.CommandContext(ctx, nc.Path, args...)
log.Debugf("Running Nuclei command: '%s'", cmd.String())View on GitHub (pinned to 909b515798)
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
Example fix
// before: opaque failure at the call site
err = nucleiConfig.RunNucleiTemplate(ctx, t.Name, nucleiTemplate, t.NucleiTargetHost)
// after: inspect the wrapped cause
if err != nil {
if errors.Is(err, ErrNucleiRunFail) {
log.Fatalf("nuclei execution failed: %v", err) // %v prints the underlying cmd error
}
return err
} Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check before running
if _, err := exec.LookPath("nuclei"); err != nil { return fmt.Errorf("nuclei not installed: %w", err) }
if _, err := os.Stat(templatePath); err != nil { return fmt.Errorf("template missing: %w", err) } Type guard
func isNucleiRunFail(err error) bool { return errors.Is(err, ErrNucleiRunFail) } Try / catch
if err := nucleiConfig.RunNucleiTemplate(ctx, name, tpl, target); err != nil {
if errors.Is(err, ErrNucleiRunFail) {
log.Printf("nuclei failed: %v", err) // wrapped cmdErr follows the sentinel
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- ErrNucleiTemplateFail
- can't find crowdsec binary: %w
- can't find cscli binary: %w
- test '%s' doesn't exist in '%s', exiting
- log file '%s' is empty, please fill it with log
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/d57e922bac486530.
Report an issue: GitHub.