crowdsecurity/crowdsec · error

unable to copy .index.json file in '%s': %w

Error message

unable to copy .index.json file in '%s': %w

What it means

Run (the public hubtest entry point) sets up the runtime environment by copying the hub's .index.json into the test's runtime hub directory. If the Copy fails (source missing, destination unwritable) the error is wrapped with the destination path.

Source

Thrown at pkg/hubtest/hubtest_item.go:614

		t.Success = true
	}

	return nil
}

func (t *HubTestItem) Run(ctx context.Context, patternDir string) error {
	var err error

	t.Success = false
	t.ErrorsList = make([]string, 0)

	// create runtime, data, hub, result folders
	if err = createDirs([]string{t.RuntimePath, t.RuntimeDBDir, t.RuntimeHubConfig.InstallDataDir, t.RuntimeHubPath, t.ResultsPath}); err != nil {
		return err
	}

	if err = Copy(t.HubIndexFile, filepath.Join(t.RuntimeHubPath, ".index.json")); err != nil {
		return fmt.Errorf("unable to copy .index.json file in '%s': %w", filepath.Join(t.RuntimeHubPath, ".index.json"), err)
	}

	// copy template config file to runtime folder
	if err = Copy(t.TemplateConfigPath, t.RuntimeConfigFilePath); err != nil {
		return fmt.Errorf("unable to copy '%s' to '%s': %w", t.TemplateConfigPath, t.RuntimeConfigFilePath, err)
	}

	// copy template profile file to runtime folder
	if err = Copy(t.TemplateProfilePath, t.RuntimeProfileFilePath); err != nil {
		return fmt.Errorf("unable to copy '%s' to '%s': %w", t.TemplateProfilePath, t.RuntimeProfileFilePath, err)
	}

	// copy template simulation file to runtime folder
	if err = Copy(t.TemplateSimulationPath, t.RuntimeSimulationFilePath); err != nil {
		return fmt.Errorf("unable to copy '%s' to '%s': %w", t.TemplateSimulationPath, t.RuntimeSimulationFilePath, err)
	}

	// copy template patterns folder to runtime folder

View on GitHub (pinned to 909b515798)

Solutions

  1. Ensure the hub index file exists (run cscli hub update / hubtest setup) and t.HubIndexFile points to it
  2. Check write permissions on the runtime hub directory
  3. Re-run the test setup so createDirs and Copy happen in a clean environment

Example fix

// before: hub index missing
ls ./hub/.index.json  # not found
// after
cscli hub update && go test ./pkg/hubtest/...
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat(hubIndexFile); err != nil { t.Fatalf("hub .index.json missing at %s — run hub update", hubIndexFile) }

Try / catch

if err := t.Run(ctx); err != nil && strings.Contains(err.Error(), "unable to copy .index.json") { /* refresh hub index and perms, rerun */ }

Prevention

When it happens

Trigger: Calling t.Run(): after createDirs succeeds, Copy(t.HubIndexFile, filepath.Join(t.RuntimeHubPath, ".index.json")) fails — HubIndexFile doesn't exist (hub not updated/downloaded) or the runtime dir is not writable.

Common situations: Hub index never generated (`cscli hub update` / hubtest setup not run); test dir created with wrong ownership; running tests as a different user without write access to runtime hub path; disk full.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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