crowdsecurity/crowdsec · error
can't get absolute path of '%s': %w
Error message
can't get absolute path of '%s': %w
What it means
installParserItem resolves the hub item's source file to an absolute path via filepath.Abs and wraps any failure from that call. filepath.Abs only fails when Getwd fails (e.g. the working directory was deleted) or the joined path is malformed, so this error almost always indicates an environment/cwd problem rather than a bad item name.
Source
Thrown at pkg/hubtest/parser.go:15
package hubtest
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
)
func (t *HubTestItem) installParserItem(item *cwhub.Item) error {
sourcePath, err := filepath.Abs(filepath.Join(t.HubPath, item.RemotePath))
if err != nil {
return fmt.Errorf("can't get absolute path of '%s': %w", sourcePath, err)
}
sourceFilename := filepath.Base(sourcePath)
// runtime/hub/parsers/s00-raw/crowdsecurity/
hubDirParserDest := filepath.Join(t.RuntimeHubPath, filepath.Dir(item.RemotePath))
// runtime/parsers/s00-raw/
itemTypeDirDest := fmt.Sprintf("%s/parsers/%s/", t.RuntimePath, item.Stage)
if err := createDirs([]string{hubDirParserDest, itemTypeDirDest}); err != nil {
return err
}
// runtime/hub/parsers/s00-raw/crowdsecurity/syslog-logs.yaml
hubDirParserPath := filepath.Join(hubDirParserDest, sourceFilename)
if err := Copy(sourcePath, hubDirParserPath); err != nil {
return fmt.Errorf("unable to copy '%s' to '%s': %w", sourcePath, hubDirParserPath, err)View on GitHub (pinned to 909b515798)
Solutions
- Check that the current working directory exists and is accessible (re-run from a valid directory).
- Verify t.HubPath is a correct absolute path in the test config (cscli hubtest flags).
- Confirm the item's RemotePath exists under HubPath: `ls <HubPath>/<RemotePath>`.
Example fix
// before
cwd, _ := os.Getwd() // may be empty if cwd deleted
runTests(cwd)
// after
cwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("working directory unavailable: %w", err)
}
runTests(cwd) Defensive patterns
Strategy: validation
Validate before calling
if cwd, err := os.Getwd(); err != nil {
return fmt.Errorf("cwd unavailable: %w", err)
}
if _, err := os.Stat(filepath.Join(hubPath, itemRemotePath)); err != nil {
return fmt.Errorf("hub item missing at %s: %w", filepath.Join(hubPath, itemRemotePath), err)
} Try / catch
if err := item.InstallParser(name); err != nil {
// absolute-path or copy failure: check cwd and hub integrity
return fmt.Errorf("install parser %s: %w", name, err)
} Prevention
- Run hubtests from a stable, existing working directory.
- Keep HubPath absolute in test configuration.
- Run `cscli hub update` before test runs.
When it happens
Trigger: Calling HubTestItem.installParser for an item whose HubPath+RemotePath join makes filepath.Abs fail — practically only when os.Getwd() errors (deleted current directory, permission issue) or the path contains invalid components.
Common situations: Running hub tests from a temp dir that was removed mid-run; running with a cwd the process cannot stat; HubPath built from an empty/incorrect config producing a broken join.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- while find parser asserts: %w
- while reading %s: %w
- while find scenario asserts: %w
- %q is a directory, not a file
- can't get absolute path of hub: %w
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/1cc90a31cec5bda8.
Report an issue: GitHub.