{"record":{"id":"e59ba0bfbbd6276d","repo":"crowdsecurity/crowdsec","slug":"can-t-get-absolute-path-of-s-w","errorCode":null,"errorMessage":"can't get absolute path of '%s': %w","messagePattern":"can't get absolute path of '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/appsecrule.go","lineNumber":17,"sourceCode":"package hubtest\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"strings\"\n\n\tlog \"github.com/sirupsen/logrus\"\n\n\t\"github.com/crowdsecurity/crowdsec/pkg/cwhub\"\n)\n\nfunc (t *HubTestItem) installAppsecRuleItem(item *cwhub.Item) error {\n\tsourcePath, err := filepath.Abs(filepath.Join(t.HubPath, item.RemotePath))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"can't get absolute path of '%s': %w\", sourcePath, err)\n\t}\n\n\tsourceFilename := filepath.Base(sourcePath)\n\n\t// runtime/hub/appsec-rules/author/appsec-rule\n\thubDirAppsecRuleDest := filepath.Join(t.RuntimeHubPath, filepath.Dir(item.RemotePath))\n\n\t// runtime/appsec-rules/\n\titemTypeDirDest := fmt.Sprintf(\"%s/appsec-rules/\", t.RuntimePath)\n\n\tif err := createDirs([]string{hubDirAppsecRuleDest, itemTypeDirDest}); err != nil {\n\t\treturn err\n\t}\n\n\t// runtime/hub/appsec-rules/crowdsecurity/rule.yaml\n\thubDirAppsecRulePath := filepath.Join(itemTypeDirDest, sourceFilename)\n\tif err := Copy(sourcePath, hubDirAppsecRulePath); err != nil {\n\t\treturn fmt.Errorf(\"unable to copy '%s' to '%s': %w\", sourcePath, hubDirAppsecRulePath, err)","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/appsecrule.go#L1-L35","documentation":"installAppsecRuleItem fails while resolving the hub item's absolute source path (filepath.Abs on HubPath + item.RemotePath). filepath.Abs only fails on malformed relative paths (e.g. unrecoverable working-directory errors), so this almost always indicates a broken hub index or hub path state.","triggerScenarios":"Calling installAppsecRule with a name that resolves to a hub item whose RemotePath joined with t.HubPath cannot be made absolute — realistically only when filepath.Abs gets an error from the working directory lookup or the joined path is pathological.","commonSituations":"Corrupt hub index entry with an empty/invalid RemotePath; running with a deleted or inaccessible current working directory (filepath.Abs relies on it for relative paths); HubPath misconfigured to an odd relative value.","solutions":["Run 'cscli hub update' to rebuild a clean hub index, then retry the test installation","Verify t.HubPath is a valid absolute path and the appsec-rule exists at HubPath/RemotePath","Ensure the process working directory exists and is accessible (filepath.Abs needs it for relative paths)"],"exampleFix":"// before\nhub := &HubTestItem{HubPath: \"\"}\nhub.installAppsecRule(\"crowdsecurity/vpatch-priv-esc\")\n// after\nhub := &HubTestItem{HubPath: \"/etc/crowdsec/hub\"}\nhub.installAppsecRule(\"crowdsecurity/vpatch-priv-esc\")","handlingStrategy":"validation","validationCode":"abs, err := filepath.Abs(filepath.Join(hubPath, item.RemotePath))\nif err != nil {\n\tlog.Fatalf(\"bad hub path for %s: %v\", item.Name, err)\n}\nif _, err := os.Stat(abs); err != nil {\n\tlog.Fatalf(\"missing rule file %s: run 'cscli hub update'\", abs)\n}","typeGuard":null,"tryCatchPattern":"if err := t.installAppsecRule(name); err != nil {\n\tif strings.Contains(err.Error(), \"can't get absolute path\") {\n\t\t// refresh hub index and retry once\n\t}\n\treturn err\n}","preventionTips":["Keep the hub index fresh ('cscli hub update') before running hub tests","Verify HubPath is absolute and points to a real checkout","Avoid deleting or renaming the process working directory while tests run"],"tags":["paths","hub","filepath"],"backgroundTag":"invalid-url-format","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"}