{"record":{"id":"39a0227b8bb8ea20","repo":"crowdsecurity/crowdsec","slug":"can-t-find-crowdsec-binary-w","errorCode":null,"errorMessage":"can't find crowdsec binary: %w","messagePattern":"can't find crowdsec binary: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/hubtest.go","lineNumber":120,"sourceCode":"\nfunc NewHubTest(hubPath string, crowdsecPath string, cscliPath string, isAppsecTest bool) (HubTest, error) {\n\thubPath, err := filepath.Abs(hubPath)\n\tif err != nil {\n\t\treturn HubTest{}, fmt.Errorf(\"can't get absolute path of hub: %w\", err)\n\t}\n\n\tsharedDataDir := filepath.Join(hubPath, \".cache\", \"data\")\n\tif err = os.MkdirAll(sharedDataDir, 0o700); err != nil {\n\t\treturn HubTest{}, fmt.Errorf(\"while creating data dir: %w\", err)\n\t}\n\n\t// we can't use hubtest without the hub\n\tif _, err = os.Stat(hubPath); os.IsNotExist(err) {\n\t\treturn HubTest{}, fmt.Errorf(\"path to hub '%s' doesn't exist, can't run\", hubPath)\n\t}\n\t// we can't use hubtest without crowdsec binary\n\tif crowdsecPath, err = resolveBinaryPath(crowdsecPath); err != nil {\n\t\treturn HubTest{}, fmt.Errorf(\"can't find crowdsec binary: %w\", err)\n\t}\n\n\t// we can't use hubtest without cscli binary\n\tif cscliPath, err = resolveBinaryPath(cscliPath); err != nil {\n\t\treturn HubTest{}, fmt.Errorf(\"can't find cscli binary: %w\", err)\n\t}\n\n\tif isAppsecTest {\n\t\tHubTestPath := filepath.Join(hubPath, \".appsec-tests\")\n\t\thubIndexFile := filepath.Join(hubPath, \".index.json\")\n\n\t\tlocal := &csconfig.LocalHubCfg{\n\t\t\tHubDir:         hubPath,\n\t\t\tHubIndexFile:   hubIndexFile,\n\t\t\tInstallDir:     HubTestPath,\n\t\t\tInstallDataDir: sharedDataDir,\n\t\t}\n","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/hubtest.go#L102-L138","documentation":"NewHubTest validates that a crowdsec binary is available before constructing a HubTest. It calls resolveBinaryPath on the provided crowdsecPath; if the path does not point to an executable file, the underlying error is wrapped in 'can't find crowdsec binary: %w' and construction aborts. Hub tests cannot run without the crowdsec binary, so this is a fail-fast guard.","triggerScenarios":"Calling hubtest.NewHubTest with a crowdsecPath that is empty, relative and not on PATH, points to a nonexistent file, or points to a non-executable file (e.g. a source directory or a file without the execute bit).","commonSituations":"Running hub tests outside the repo build tree where ./crowdsec was never built; passing an empty string expecting PATH lookup but no crowdsec in $PATH; using a stale path after `make clean`; CI images that build cscli but not crowdsec.","solutions":["Build the binary first: run `make build` in the crowdsec repo so ./crowdsec exists, then pass its absolute path to NewHubTest.","Verify the path: `ls -l <crowdsecPath>` and ensure it exists and is executable (`chmod +x` if needed).","If relying on PATH resolution, confirm `command -v crowdsec` finds it and install/export the binary to PATH.","Pass an explicit absolute path instead of a relative one when the working directory is not the repo root."],"exampleFix":"// before\nht, err := hubtest.NewHubTest(ctx, hubPath, \"crowdsec\", \"cscli\", false)\n// after\nht, err := hubtest.NewHubTest(ctx, hubPath, \"/absolute/path/to/crowdsec\", \"/absolute/path/to/cscli\", false)","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(crowdsecPath); err != nil {\n    // resolve or build the binary first\n    out, err := exec.Command(\"make\", \"build\").Output()\n    _ = out\n}\ninfo, err := os.Stat(crowdsecPath)\nif err != nil || info.IsDir() || info.Mode()&0o111 == 0 {\n    return fmt.Errorf(\"crowdsec binary missing or not executable: %s\", crowdsecPath)\n}","typeGuard":"func binaryReady(p string) bool {\n    fi, err := os.Stat(p)\n    return err == nil && !fi.IsDir() && fi.Mode()&0o111 != 0\n}","tryCatchPattern":null,"preventionTips":["Always run `make build` before hub tests and pass absolute binary paths.","Check `command -v crowdsec` in CI before running hub tests.","Never `make clean` between build and test steps in the same job."],"tags":["binary","hubtest","file-not-found","testing"],"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-14T05:17:10.506Z"}