crowdsecurity/crowdsec · error

can't find crowdsec binary: %w

Error message

can't find crowdsec binary: %w

What it means

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.

Source

Thrown at pkg/hubtest/hubtest.go:120

func NewHubTest(hubPath string, crowdsecPath string, cscliPath string, isAppsecTest bool) (HubTest, error) {
	hubPath, err := filepath.Abs(hubPath)
	if err != nil {
		return HubTest{}, fmt.Errorf("can't get absolute path of hub: %w", err)
	}

	sharedDataDir := filepath.Join(hubPath, ".cache", "data")
	if err = os.MkdirAll(sharedDataDir, 0o700); err != nil {
		return HubTest{}, fmt.Errorf("while creating data dir: %w", err)
	}

	// we can't use hubtest without the hub
	if _, err = os.Stat(hubPath); os.IsNotExist(err) {
		return HubTest{}, fmt.Errorf("path to hub '%s' doesn't exist, can't run", hubPath)
	}
	// we can't use hubtest without crowdsec binary
	if crowdsecPath, err = resolveBinaryPath(crowdsecPath); err != nil {
		return HubTest{}, fmt.Errorf("can't find crowdsec binary: %w", err)
	}

	// we can't use hubtest without cscli binary
	if cscliPath, err = resolveBinaryPath(cscliPath); err != nil {
		return HubTest{}, fmt.Errorf("can't find cscli binary: %w", err)
	}

	if isAppsecTest {
		HubTestPath := filepath.Join(hubPath, ".appsec-tests")
		hubIndexFile := filepath.Join(hubPath, ".index.json")

		local := &csconfig.LocalHubCfg{
			HubDir:         hubPath,
			HubIndexFile:   hubIndexFile,
			InstallDir:     HubTestPath,
			InstallDataDir: sharedDataDir,
		}

View on GitHub (pinned to 909b515798)

Solutions

  1. Build the binary first: run `make build` in the crowdsec repo so ./crowdsec exists, then pass its absolute path to NewHubTest.
  2. Verify the path: `ls -l <crowdsecPath>` and ensure it exists and is executable (`chmod +x` if needed).
  3. If relying on PATH resolution, confirm `command -v crowdsec` finds it and install/export the binary to PATH.
  4. Pass an explicit absolute path instead of a relative one when the working directory is not the repo root.

Example fix

// before
ht, err := hubtest.NewHubTest(ctx, hubPath, "crowdsec", "cscli", false)
// after
ht, err := hubtest.NewHubTest(ctx, hubPath, "/absolute/path/to/crowdsec", "/absolute/path/to/cscli", false)
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat(crowdsecPath); err != nil {
    // resolve or build the binary first
    out, err := exec.Command("make", "build").Output()
    _ = out
}
info, err := os.Stat(crowdsecPath)
if err != nil || info.IsDir() || info.Mode()&0o111 == 0 {
    return fmt.Errorf("crowdsec binary missing or not executable: %s", crowdsecPath)
}

Type guard

func binaryReady(p string) bool {
    fi, err := os.Stat(p)
    return err == nil && !fi.IsDir() && fi.Mode()&0o111 != 0
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/39a0227b8bb8ea20. Report an issue: GitHub.