{"record":{"id":"49de8d34d6944d24","repo":"crowdsecurity/crowdsec","slug":"unable-to-copy-s-to-s-w-49de8d","errorCode":null,"errorMessage":"unable to copy '%s' to '%s': %w","messagePattern":"unable to copy '(.+?)' to '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/hubtest_item.go","lineNumber":619,"sourceCode":"\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\n\tif err = CopyDir(patternDir, t.RuntimePatternsPath); err != nil {\n\t\treturn fmt.Errorf(\"unable to copy 'patterns' from '%s' to '%s': %w\", patternDir, t.RuntimePatternsPath, err)\n\t}\n\n\t// create the appsec-configs dir","sourceCodeStart":601,"sourceCodeEnd":637,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/hubtest_item.go#L601-L637","documentation":"This error is returned by HubTestItem.Run in pkg/hubtest when the copy of the test's template crowdsec config file (t.TemplateConfigPath) into the test runtime folder (t.RuntimeConfigFilePath) fails. It wraps the underlying os-level error (typically the source file missing, or the destination being unwritable). It means the hubtest runtime environment could not be prepared, so the test never runs.","triggerScenarios":"Calling cscli hubtest run (which invokes HubTestItem.Run) when the template config file referenced by t.TemplateConfigPath does not exist, when t.RuntimeConfigFilePath's parent directory was not created or is not writable, or when disk I/O fails mid-copy.","commonSituations":"Running hub tests from a source tree where the config template was not built/copied; running as a user without write permission on the test runtime directory; read-only filesystem or full disk; a partially-cleaned runtime folder from a previous failed test run.","solutions":["Check the wrapped error: if it says 'no such file or directory' for the source, verify t.TemplateConfigPath exists before running the test.","Verify the runtime directory (t.RuntimePath) exists and is writable by the current user; re-run createDirs or remove stale runtime folders.","Run the hub test with sufficient permissions (e.g. the same user that owns the crowdsec source tree).","Check free disk space and that the destination path is not a directory."],"exampleFix":"// before: calling Run with a missing template config\nitem.Run(ctx, patternDir) // fails if config.yaml template absent\n// after: pre-validate templates\nif _, err := os.Stat(item.TemplateConfigPath); err != nil {\n    return fmt.Errorf(\"template config missing: %w\", err)\n}\nif err := item.Run(ctx, patternDir); err != nil { ... }","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(item.TemplateConfigPath); err != nil {\n    return fmt.Errorf(\"config template missing: %w\", err)\n}\nif err := os.MkdirAll(filepath.Dir(item.RuntimeConfigFilePath), 0o755); err != nil {\n    return fmt.Errorf(\"runtime dir not writable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := item.Run(ctx, patternDir); err != nil {\n    var perr *os.PathError\n    if errors.As(err, &perr) {\n        log.Errorf(\"copy failed for %s: %v\", perr.Path, perr.Err)\n    }\n    return err\n}","preventionTips":["Stat every template path before invoking Run.","Always create and clean runtime directories via createDirs at test start.","Run hub tests as the user owning the source tree.","Check disk space in CI before running test suites."],"tags":["go","file-copy","hubtest","filesystem"],"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-14T05:17:10.506Z"}