{"record":{"id":"809c77e1ba1aa420","repo":"crowdsecurity/crowdsec","slug":"test-s-doesn-t-exist-in-s-exiting","errorCode":null,"errorMessage":"test '%s' doesn't exist in '%s', exiting","messagePattern":"test '(.+?)' doesn't exist in '(.+?)', exiting","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/hubtest_item.go","lineNumber":332,"sourceCode":"\t\t\tlog.Infof(\"%s - %s\", emoji.GreenCircle, line)\n\t\t}\n\t}\n\n\tif len(failures) > 0 {\n\t\tlog.Errorf(\"Failure log -------------\")\n\n\t\tfor _, line := range failures {\n\t\t\tlog.Infof(\"%s - %s\", emoji.RedCircle, line)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (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","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/hubtest_item.go#L314-L350","documentation":"RunWithNucleiTemplate first checks that the test directory exists under HubTestPath before executing crowdsec commands for a nuclei-based test. If <HubTestPath>/<Name> is missing, it returns 'test <name> doesn't exist in <path>, exiting'. It is a preflight guard against running commands in a nonexistent runtime.","triggerScenarios":"Calling HubTestItem.Run (nuclei path) with a test whose directory was deleted, never created (LoadTestItem/NewTest not run or failed), or whose Name doesn't match an existing directory under HubTestPath.","commonSituations":"Typo in the test name; tests directory not copied/cloned into place; previous run cleaned up the test directory; running a hub test by name from the wrong working directory so HubTestPath points elsewhere.","solutions":["Verify the directory exists: `ls <HubTestPath>/<testName>`; if missing, re-clone/copy the hub tests or re-run the loader that creates the item.","Correct the test name passed to Run so it matches an existing directory exactly.","Ensure HubTestPath is set to the actual hub tests directory (check for typos/relative paths) before constructing/running the item.","If a previous cleanup deleted it, recreate the test item via LoadTestItem before RunWithNucleiTemplate."],"exampleFix":"null","handlingStrategy":"validation","validationCode":"testPath := filepath.Join(hubTestPath, name)\nif fi, err := os.Stat(testPath); err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"test %s not present under %s\", name, hubTestPath)\n}","typeGuard":"func testExists(hubTestPath, name string) bool {\n    fi, err := os.Stat(filepath.Join(hubTestPath, name))\n    return err == nil && fi.IsDir()\n}","tryCatchPattern":"err := item.Run(ctx)\nif err != nil && strings.Contains(err.Error(), \"doesn't exist in\") {\n    // reload or re-clone the hub tests, then re-create the item via LoadTestItem\n}","preventionTips":["Load the test item (LoadTestItem) before calling Run — don't run names that were never loaded.","Verify HubTestPath points at the real hub tests directory.","Avoid cleanup steps that delete test directories mid-suite."],"tags":["hubtest","nuclei","file-not-found"],"backgroundTag":"directory-not-found","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}