{"record":{"id":"9fe5f7a81d8a9a59","repo":"crowdsecurity/crowdsec","slug":"can-t-get-absolute-path-of-hub-w","errorCode":null,"errorMessage":"can't get absolute path of hub: %w","messagePattern":"can't get absolute path of hub: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/hubtest.go","lineNumber":106,"sourceCode":"\tf, err := os.Stat(resolved)\n\tswitch {\n\tcase errors.Is(err, fs.ErrNotExist):\n\t\treturn \"\", err\n\tcase err != nil:\n\t\treturn \"\", err\n\t}\n\n\tif f.IsDir() {\n\t\treturn \"\", fmt.Errorf(\"%q is a directory, not a file\", resolved)\n\t}\n\n\treturn resolved, nil\n}\n\nfunc NewHubTest(hubPath string, crowdsecPath string, cscliPath string, isAppsecTest bool) (HubTest, error) {\n\thubPath, err := filepath.Abs(hubPath)\n\tif err != nil {\n\t\treturn HubTest{}, fmt.Errorf(\"can't get absolute path of hub: %w\", err)\n\t}\n\n\tsharedDataDir := filepath.Join(hubPath, \".cache\", \"data\")\n\tif err = os.MkdirAll(sharedDataDir, 0o700); err != nil {\n\t\treturn HubTest{}, fmt.Errorf(\"while creating data dir: %w\", err)\n\t}\n\n\t// we can't use hubtest without the hub\n\tif _, err = os.Stat(hubPath); os.IsNotExist(err) {\n\t\treturn HubTest{}, fmt.Errorf(\"path to hub '%s' doesn't exist, can't run\", hubPath)\n\t}\n\t// we can't use hubtest without crowdsec binary\n\tif crowdsecPath, err = resolveBinaryPath(crowdsecPath); err != nil {\n\t\treturn HubTest{}, fmt.Errorf(\"can't find crowdsec binary: %w\", err)\n\t}\n\n\t// we can't use hubtest without cscli binary\n\tif cscliPath, err = resolveBinaryPath(cscliPath); err != nil {","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/hubtest.go#L88-L124","documentation":"NewHubTest first converts hubPath to an absolute path with filepath.Abs. Abs essentially never fails on sane input (it only fails on pathological paths), so 'can't get absolute path of hub' indicates the OS rejected the path manipulation (e.g. working directory unreadable).","triggerScenarios":"Calling NewHubTest(hubPath, ...) when filepath.Abs fails because the current working directory cannot be determined (deleted cwd, permission issues).","commonSituations":"Running hubtest from a directory that was deleted while the shell was inside it; running inside a container/sandbox where getwd fails.","solutions":["cd to a valid existing directory before running hubtest, or pass an absolute hubPath","Verify the current working directory exists (pwd) and recreate it if deleted","Pass an already-absolute hub path so Abs has no relative component to resolve against cwd"],"exampleFix":"// before\ncd /tmp/deleted-dir && hubtest run ...\n// after\ncd /tmp && hubtest run ...","handlingStrategy":"validation","validationCode":"if !filepath.IsAbs(hubPath) {\n    if _, err := os.Getwd(); err != nil { return err } // cwd must be valid\n}\nabs, err := filepath.Abs(hubPath); if err != nil { return err }","typeGuard":null,"tryCatchPattern":"ht, err := hubtest.NewHubTest(hubPath, ...)\nif err != nil {\n    if strings.Contains(err.Error(), \"absolute path of hub\") { /* re-run from a valid cwd */ }\n}","preventionTips":["Don't run hubtest from a deleted working directory","Prefer passing absolute hub paths","Avoid containers/sandboxes where os.Getwd fails"],"tags":["filesystem","paths","hubtest"],"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-14T00:17:10.932Z"}