crowdsecurity/crowdsec · error
can't get absolute path of hub: %w
Error message
can't get absolute path of hub: %w
What it means
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).
Source
Thrown at pkg/hubtest/hubtest.go:106
f, err := os.Stat(resolved)
switch {
case errors.Is(err, fs.ErrNotExist):
return "", err
case err != nil:
return "", err
}
if f.IsDir() {
return "", fmt.Errorf("%q is a directory, not a file", resolved)
}
return resolved, nil
}
func NewHubTest(hubPath string, crowdsecPath string, cscliPath string, isAppsecTest bool) (HubTest, error) {
hubPath, err := filepath.Abs(hubPath)
if err != nil {
return HubTest{}, fmt.Errorf("can't get absolute path of hub: %w", err)
}
sharedDataDir := filepath.Join(hubPath, ".cache", "data")
if err = os.MkdirAll(sharedDataDir, 0o700); err != nil {
return HubTest{}, fmt.Errorf("while creating data dir: %w", err)
}
// we can't use hubtest without the hub
if _, err = os.Stat(hubPath); os.IsNotExist(err) {
return HubTest{}, fmt.Errorf("path to hub '%s' doesn't exist, can't run", hubPath)
}
// we can't use hubtest without crowdsec binary
if crowdsecPath, err = resolveBinaryPath(crowdsecPath); err != nil {
return HubTest{}, fmt.Errorf("can't find crowdsec binary: %w", err)
}
// we can't use hubtest without cscli binary
if cscliPath, err = resolveBinaryPath(cscliPath); err != nil {View on GitHub (pinned to 909b515798)
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
Example fix
// before cd /tmp/deleted-dir && hubtest run ... // after cd /tmp && hubtest run ...
Defensive patterns
Strategy: validation
Validate before calling
if !filepath.IsAbs(hubPath) {
if _, err := os.Getwd(); err != nil { return err } // cwd must be valid
}
abs, err := filepath.Abs(hubPath); if err != nil { return err } Try / catch
ht, err := hubtest.NewHubTest(hubPath, ...)
if err != nil {
if strings.Contains(err.Error(), "absolute path of hub") { /* re-run from a valid cwd */ }
} Prevention
- Don't run hubtest from a deleted working directory
- Prefer passing absolute hub paths
- Avoid containers/sandboxes where os.Getwd fails
When it happens
Trigger: Calling NewHubTest(hubPath, ...) when filepath.Abs fails because the current working directory cannot be determined (deleted cwd, permission issues).
Common situations: Running hubtest from a directory that was deleted while the shell was inside it; running inside a container/sandbox where getwd fails.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- failed to get absolute path of %q: %w
- while find parser asserts: %w
- while reading %s: %w
- while find scenario asserts: %w
- %q is a directory, not a file
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/9fe5f7a81d8a9a59.
Report an issue: GitHub.