crowdsecurity/crowdsec · error

basename: missing argument

Error message

basename: missing argument

What it means

The basename expr helper in pkg/hubtest/helpers.go returns this error when called with no arguments or a nil first argument. It is a template/expression helper used in hub tests, so a malformed expression yields this error.

Source

Thrown at pkg/hubtest/helpers.go:12

package hubtest

import (
	"errors"
	"fmt"
	"path/filepath"
)

func basename(params ...any) (any, error) {
	// keep nilaway happy
	if len(params) == 0 || params[0] == nil {
		return "", errors.New("basename: missing argument")
	}

	// keep forcetypeassert happy
	s, ok := params[0].(string)
	if !ok {
		return "", fmt.Errorf("basename: want string, got %T", params[0])
	}

	return filepath.Base(s), nil
}

View on GitHub (pinned to 909b515798)

Solutions

  1. Pass a string argument: basename('some/file/name.yaml')
  2. Ensure the variable inside basename(...) is populated before evaluation
  3. Check the expr expression syntax in the hub test file for a dropped parameter

Example fix

// before
basename()
// after
basename(evt.Parsed.filename)
Defensive patterns

Strategy: validation

Validate before calling

if arg == nil || arg == "" { skip := true } else { out, _ := basename(arg) }

Type guard

func safeBasename(params ...any) (any, error) { if len(params) == 0 || params[0] == nil { return "", errors.New("basename needs a string argument") }; return basename(params...) }

Try / catch

out, err := basename(input)
if err != nil { log.Warnf("basename failed: %v", err) }

Prevention

When it happens

Trigger: Invoking basename() with zero params in an expr expression inside a hub test file, or basename(nil).

Common situations: Hand-edited test YAML where the basename() expression lost its argument; dynamic expression evaluation where the variable feeding basename was nil.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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