crowdsecurity/crowdsec · error

can't get absolute path of '%s': %w

Error message

can't get absolute path of '%s': %w

What it means

installPostoverflowItem computes the absolute path of a hub postoverflow item (HubPath + RemotePath) to copy it into the test runtime hub. filepath.Abs fails only in exotic conditions (e.g. issues resolving the working directory), and the item's RemotePath is reported for debugging. It aborts the hub test item install.

Source

Thrown at pkg/hubtest/postoverflow.go:15

package hubtest

import (
	"fmt"
	"os"
	"path/filepath"
	"strings"

	"github.com/crowdsecurity/crowdsec/pkg/cwhub"
)

func (t *HubTestItem) installPostoverflowItem(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/postoverflows/s00-enrich/crowdsecurity/
	hubDirPostoverflowDest := filepath.Join(t.RuntimeHubPath, filepath.Dir(item.RemotePath))

	// runtime/postoverflows/s00-enrich
	itemTypeDirDest := fmt.Sprintf("%s/postoverflows/%s/", t.RuntimePath, item.Stage)

	if err := createDirs([]string{hubDirPostoverflowDest, itemTypeDirDest}); err != nil {
		return err
	}

	// runtime/hub/postoverflows/s00-enrich/crowdsecurity/rdns.yaml
	hubDirPostoverflowPath := filepath.Join(hubDirPostoverflowDest, sourceFilename)
	if err := Copy(sourcePath, hubDirPostoverflowPath); err != nil {
		return fmt.Errorf("unable to copy '%s' to '%s': %w", sourcePath, hubDirPostoverflowPath, err)

View on GitHub (pinned to 909b515798)

Solutions

  1. Verify the test item's HubPath points to an existing, absolute hub directory
  2. Run the tests from a valid working directory
  3. Check the item's RemotePath is set (populated by hub load)
  4. Print/validate t.HubPath before the install call

Example fix

// before
if t.HubPath == "" { ... later Abs fails ... }
// after
if t.HubPath == "" {
    return fmt.Errorf("HubPath is empty, cannot install postoverflow")
}
Defensive patterns

Strategy: validation

Validate before calling

if t.HubPath == "" {
    return fmt.Errorf("HubPath must be set before installing postoverflows")
}
if _, err := os.Stat(filepath.Join(t.HubPath, item.RemotePath)); err != nil {
    return fmt.Errorf("hub item missing: %w", err)
}

Try / catch

if err := t.installPostoverflow(item); err != nil {
    if strings.Contains(err.Error(), "can't get absolute path") {
        log.Errorf("bad hub path config: %v", err)
    }
    return err
}

Prevention

When it happens

Trigger: installPostoverflowItem invoked with an item whose combined HubPath/RemotePath cannot be resolved to an absolute path — essentially when the process working directory is invalid or HubPath is empty/malformed.

Common situations: Test item configured with an empty HubPath field; running tests from a deleted working directory; misconfigured hub path in the hubtest definition.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/12b24625cc1b6129. Report an issue: GitHub.