crowdsecurity/crowdsec · error

unable to install hub in '%s': %w

Error message

unable to install hub in '%s': %w

What it means

This error is returned by HubTestItem.Run when t.InstallHub fails to install the hub (index, collections, parsers, etc.) into the test's runtime hub directory. It means the test environment is assembled but hub content could not be installed, so the test cannot execute; the underlying hub error (often network or index issues) is wrapped.

Source

Thrown at pkg/hubtest/hubtest_item.go:664

		if err = Copy(t.TemplateAcquisPath, t.RuntimeAcquisFilePath); err != nil {
			return fmt.Errorf("unable to copy '%s' to '%s': %w", t.TemplateAcquisPath, t.RuntimeAcquisFilePath, err)
		}

		log.Debugf("copying %s to %s", t.TemplateAppsecProfilePath, filepath.Join(t.RuntimePath, "appsec-configs", "config.yaml"))
		// copy template appsec-config file to runtime folder
		if err = Copy(t.TemplateAppsecProfilePath, filepath.Join(t.RuntimePath, "appsec-configs", "config.yaml")); err != nil {
			return fmt.Errorf("unable to copy '%s' to '%s': %w", t.TemplateAppsecProfilePath, filepath.Join(t.RuntimePath, "appsec-configs", "config.yaml"), err)
		}
	} else { // otherwise we drop a blank acquis file
		if err = os.WriteFile(t.RuntimeAcquisFilePath, []byte(""), os.ModePerm); err != nil {
			return fmt.Errorf("unable to write blank acquis file '%s': %w", t.RuntimeAcquisFilePath, err)
		}
	}

	// install the hub in the runtime folder
	if err = t.InstallHub(ctx); err != nil {
		return fmt.Errorf("unable to install hub in '%s': %w", t.RuntimeHubPath, err)
	}

	if t.Config.LogFile != "" {
		return t.RunWithLogFile(ctx)
	}

	if t.Config.NucleiTemplate != "" {
		return t.RunWithNucleiTemplate(ctx)
	}

	return fmt.Errorf("log file or nuclei template must be set in '%s'", t.Name)
}

View on GitHub (pinned to 909b515798)

Solutions

  1. Read the wrapped InstallHub error: if it is a network failure, fix connectivity or proxy settings and retry.
  2. Refresh the hub index with `cscli hub update` before running tests.
  3. Delete the runtime hub directory and re-run so installation starts from a clean state.
  4. Verify the copied .index.json (t.HubIndexFile) is valid JSON and corresponds to the installed hub version.

Example fix

// before
item.Run(ctx, patternDir) // "unable to install hub in ...": download failed
// after: preflight hub index and connectivity
if err := hub.Update(); err != nil {
    return fmt.Errorf("run 'cscli hub update' first: %w", err)
}
err := item.Run(ctx, patternDir)
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := os.Stat(item.HubIndexFile); err != nil {
    return fmt.Errorf("hub index missing, run 'cscli hub update': %w", err)
}
if _, err := os.Stat(item.RuntimeHubPath); err != nil {
    os.MkdirAll(item.RuntimeHubPath, 0o755)
}

Try / catch

if err := item.Run(ctx, patternDir); err != nil {
    if strings.Contains(err.Error(), "unable to install hub") {
        os.RemoveAll(item.RuntimeHubPath)
        if herr := hub.Update(); herr != nil {
            return fmt.Errorf("hub unreachable, check network/proxy: %w", herr)
        }
        return item.Run(ctx, patternDir)
    }
    return err
}

Prevention

When it happens

Trigger: Calling Run when the hub index (.index.json) is invalid or missing taints, downloading hub content fails (network offline / CAPI unreachable), or writing to t.RuntimeHubPath fails.

Common situations: Running hub tests behind a proxy or with no internet access; stale or corrupted .index.json copied into the runtime; hub taint/versions mismatch; disk full in the runtime hub path.

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


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