{"record":{"id":"5a66067235b76b04","repo":"crowdsecurity/crowdsec","slug":"unable-to-copy-index-json-file-in-s-w","errorCode":null,"errorMessage":"unable to copy .index.json file in '%s': %w","messagePattern":"unable to copy \\.index\\.json file in '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/hubtest_item.go","lineNumber":614,"sourceCode":"\t\tt.Success = true\n\t}\n\n\treturn nil\n}\n\nfunc (t *HubTestItem) Run(ctx context.Context, patternDir string) error {\n\tvar err error\n\n\tt.Success = false\n\tt.ErrorsList = make([]string, 0)\n\n\t// create runtime, data, hub, result folders\n\tif err = createDirs([]string{t.RuntimePath, t.RuntimeDBDir, t.RuntimeHubConfig.InstallDataDir, t.RuntimeHubPath, t.ResultsPath}); err != nil {\n\t\treturn err\n\t}\n\n\tif err = Copy(t.HubIndexFile, filepath.Join(t.RuntimeHubPath, \".index.json\")); err != nil {\n\t\treturn fmt.Errorf(\"unable to copy .index.json file in '%s': %w\", filepath.Join(t.RuntimeHubPath, \".index.json\"), err)\n\t}\n\n\t// copy template config file to runtime folder\n\tif err = Copy(t.TemplateConfigPath, t.RuntimeConfigFilePath); err != nil {\n\t\treturn fmt.Errorf(\"unable to copy '%s' to '%s': %w\", t.TemplateConfigPath, t.RuntimeConfigFilePath, err)\n\t}\n\n\t// copy template profile file to runtime folder\n\tif err = Copy(t.TemplateProfilePath, t.RuntimeProfileFilePath); err != nil {\n\t\treturn fmt.Errorf(\"unable to copy '%s' to '%s': %w\", t.TemplateProfilePath, t.RuntimeProfileFilePath, err)\n\t}\n\n\t// copy template simulation file to runtime folder\n\tif err = Copy(t.TemplateSimulationPath, t.RuntimeSimulationFilePath); err != nil {\n\t\treturn fmt.Errorf(\"unable to copy '%s' to '%s': %w\", t.TemplateSimulationPath, t.RuntimeSimulationFilePath, err)\n\t}\n\n\t// copy template patterns folder to runtime folder","sourceCodeStart":596,"sourceCodeEnd":632,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/hubtest_item.go#L596-L632","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the hub index file exists (run cscli hub update / hubtest setup) and t.HubIndexFile points to it","Check write permissions on the runtime hub directory","Re-run the test setup so createDirs and Copy happen in a clean environment"],"exampleFix":"// before: hub index missing\nls ./hub/.index.json  # not found\n// after\ncscli hub update && go test ./pkg/hubtest/...","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(hubIndexFile); err != nil { t.Fatalf(\"hub .index.json missing at %s — run hub update\", hubIndexFile) }","typeGuard":null,"tryCatchPattern":"if err := t.Run(ctx); err != nil && strings.Contains(err.Error(), \"unable to copy .index.json\") { /* refresh hub index and perms, rerun */ }","preventionTips":["Run `cscli hub update`/hubtest setup before tests","Ensure the test user owns the runtime directories","Check disk space in CI runners"],"tags":["hubtest","file-copy","setup","testing"],"backgroundTag":"file-not-found","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}