{"record":{"id":"cd27bcf89f90b177","repo":"crowdsecurity/crowdsec","slug":"unable-to-copy-patterns-from-s-to-s-w","errorCode":null,"errorMessage":"unable to copy 'patterns' from '%s' to '%s': %w","messagePattern":"unable to copy 'patterns' from '(.+?)' to '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/hubtest_item.go","lineNumber":634,"sourceCode":"\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\n\tif err = os.MkdirAll(filepath.Join(t.RuntimePath, \"appsec-configs\"), os.ModePerm); err != nil {\n\t\treturn fmt.Errorf(\"unable to create folder '%s': %w\", t.RuntimePath, err)\n\t}\n\n\t// if it's an appsec rule test, we need acquis and appsec profile\n\tif len(t.Config.AppsecRules) > 0 {\n\t\t// copy template acquis file to runtime folder\n\t\tlog.Debugf(\"copying %s to %s\", t.TemplateAcquisPath, t.RuntimeAcquisFilePath)\n\n\t\tif err = Copy(t.TemplateAcquisPath, t.RuntimeAcquisFilePath); err != nil {\n\t\t\treturn fmt.Errorf(\"unable to copy '%s' to '%s': %w\", t.TemplateAcquisPath, t.RuntimeAcquisFilePath, err)\n\t\t}\n\n\t\tlog.Debugf(\"copying %s to %s\", t.TemplateAppsecProfilePath, filepath.Join(t.RuntimePath, \"appsec-configs\", \"config.yaml\"))\n\t\t// copy template appsec-config file to runtime folder","sourceCodeStart":616,"sourceCodeEnd":652,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/hubtest_item.go#L616-L652","documentation":"This error is returned by HubTestItem.Run when CopyDir fails to recursively copy the crowdsec patterns folder (patternDir, e.g. the hub's data/patterns directory) into the runtime folder (t.RuntimePatternsPath). It wraps the error from walking/reading the source tree or creating destination files.","triggerScenarios":"Calling HubTestItem.Run when patternDir does not exist (patterns not downloaded/installed), a file inside patternDir is unreadable, or the runtime patterns destination cannot be created/written.","commonSituations":"Running hub tests before `cscli hub update`/install populated the patterns directory; pointing the tests at the wrong patternDir; permission issues on the hub data directory; interrupted previous copy leaving a corrupt destination.","solutions":["Verify patternDir exists and contains pattern files; run `cscli hub update` / install data files if missing.","Confirm the correct patternDir is passed to Run (usually the hub's installed data/patterns path).","Delete t.RuntimePatternsPath from a previous failed run and retry.","Check read permissions on the source patterns tree and write permissions on the runtime directory."],"exampleFix":"// before\nitem.Run(ctx, \"/missing/hub/data/patterns\") // fails\n// after\npatternDir := filepath.Join(hubDataDir, \"patterns\")\nif _, err := os.Stat(patternDir); err != nil {\n    return fmt.Errorf(\"run 'cscli hub update' first: %w\", err)\n}\nerr := item.Run(ctx, patternDir)","handlingStrategy":"validation","validationCode":"info, err := os.Stat(patternDir)\nif err != nil {\n    return fmt.Errorf(\"patterns dir missing, run 'cscli hub update': %w\", err)\n}\nif !info.IsDir() {\n    return fmt.Errorf(\"%s is not a directory\", patternDir)\n}","typeGuard":null,"tryCatchPattern":"if err := item.Run(ctx, patternDir); err != nil {\n    if os.IsNotExist(errors.Unwrap(err)) {\n        return fmt.Errorf(\"patterns not installed; run cscli hub update\")\n    }\n    return err\n}","preventionTips":["Run `cscli hub update`/install before hub tests so the patterns directory is populated.","Pass the canonical hub data/patterns path to Run, not an ad-hoc path.","Clean t.RuntimePatternsPath after failed runs.","In CI, cache the patterns directory but verify it is non-empty before use."],"tags":["go","directory-copy","hubtest","patterns"],"backgroundTag":"directory-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"}