{"record":{"id":"6d237e3422c75172","repo":"crowdsecurity/crowdsec","slug":"fail-to-run-s-for-test-s-w","errorCode":null,"errorMessage":"fail to run '%s' for test '%s': %w","messagePattern":"fail to run '(.+?)' for test '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/hubtest_item.go","lineNumber":347,"sourceCode":"func (t *HubTestItem) RunWithNucleiTemplate(ctx context.Context) error {\n\ttestPath := filepath.Join(t.HubTestPath, t.Name)\n\tif _, err := os.Stat(testPath); os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"test '%s' doesn't exist in '%s', exiting\", t.Name, t.HubTestPath)\n\t}\n\n\tcrowdsecLogFile := filepath.Join(t.RuntimePath, \"log\", \"crowdsec.log\")\n\n\t// machine add\n\tcmdArgs := []string{\"-c\", t.RuntimeConfigFilePath, \"machines\", \"add\", \"testMachine\", \"--force\", \"--auto\"}\n\tcscliRegisterCmd := exec.CommandContext(ctx, t.CscliPath, cmdArgs...)\n\tcscliRegisterCmd.Dir = testPath\n\tcscliRegisterCmd.Env = []string{\"TESTDIR=\" + testPath, \"DATADIR=\" + t.RuntimeHubConfig.InstallDataDir, \"TZ=UTC\"}\n\n\toutput, err := cscliRegisterCmd.CombinedOutput()\n\tif err != nil {\n\t\tif !strings.Contains(string(output), \"unable to create machine: user 'testMachine': user already exist\") {\n\t\t\tfmt.Fprintln(os.Stdout, string(output))\n\t\t\treturn fmt.Errorf(\"fail to run '%s' for test '%s': %w\", cscliRegisterCmd.String(), t.Name, err)\n\t\t}\n\t}\n\n\t// hardcode bouncer key\n\tcmdArgs = []string{\"-c\", t.RuntimeConfigFilePath, \"bouncers\", \"add\", \"appsectests\", \"-k\", TestBouncerAPIKey}\n\tcscliBouncerCmd := exec.CommandContext(ctx, t.CscliPath, cmdArgs...)\n\tcscliBouncerCmd.Dir = testPath\n\tcscliBouncerCmd.Env = []string{\"TESTDIR=\" + testPath, \"DATADIR=\" + t.RuntimeHubConfig.InstallDataDir, \"TZ=UTC\"}\n\n\toutput, err = cscliBouncerCmd.CombinedOutput()\n\tif err != nil {\n\t\tif !strings.Contains(string(output), \"unable to create bouncer: bouncer appsectests already exists\") {\n\t\t\tfmt.Fprintln(os.Stdout, string(output))\n\t\t\treturn fmt.Errorf(\"fail to run '%s' for test '%s': %w\", cscliRegisterCmd.String(), t.Name, err)\n\t\t}\n\t}\n\n\t// start crowdsec service","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/hubtest_item.go#L329-L365","documentation":"HubTestItem.RunWithNucleiTemplate runs `cscli machines register` as a subprocess to register a test machine before running an AppSec/nuclei test. If the command exits non-zero and its output does not contain the tolerated 'user already exist' message, the test is aborted with this wrapped error. It signals that the test-environment bootstrap failed, not that the security test itself failed.","triggerScenarios":"Calling HubTestItem.Run on an AppSec test whose setup invokes cscli register against a LAPI that refuses or errors on machine registration (other than the already-exist case).","commonSituations":"LAPI not running or wrong API URL in the test config; an existing machine 'testMachine' with different credentials causing a different error string; TLS/auth misconfiguration; cscli binary version mismatch; DATADIR pointing at a broken or read-only data dir.","solutions":["Ensure the LAPI is reachable and running at the address configured in the test's RuntimeConfigFilePath before running the test","Inspect the printed subprocess output above the error for the real cscli failure cause","Delete stale test data (machines) from the install DATADIR so registration succeeds cleanly","Verify TZ/TESTDIR/DATADIR env and cscli path are correct for the test harness"],"exampleFix":"// before\noutput, err := cscliRegisterCmd.CombinedOutput()\nif err != nil { ... return fmt.Errorf(\"fail to run '%s' for test '%s': %w\", ...) }\n// after\n// start LAPI first, e.g. in test harness: crowdsec -c dev.yaml & (or docker localapi) before running hubtest","handlingStrategy":"try-catch","validationCode":"if _, err := net.Dial(\"tcp\", lapiAddr); err != nil { t.Skipf(\"LAPI not reachable: %v\", err) }","typeGuard":null,"tryCatchPattern":"if err := test.Run(ctx); err != nil {\n\tif strings.Contains(err.Error(), \"fail to run\") {\n\t\tlog.Printf(\"setup command failed, check cscli/LAPI: %v\", err)\n\t}\n}","preventionTips":["Always start LAPI before running AppSec hub tests","Clean the test DATADIR between runs to avoid stale machine state","Capture and inspect the printed subprocess output on any setup failure"],"tags":["subprocess","cscli","appsec","test-harness","lapi"],"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"}