crowdsecurity/crowdsec · error

feature flag '%s': %w

Error message

feature flag '%s': %w

What it means

FeatureRegister.RegisterFeature validates the feature name before adding it to the registry; if validateFeatureName rejects the name, the error is wrapped as "feature flag '<name>': <reason>". It fails registration at startup rather than allowing an invalid flag to be set later.

Source

Thrown at pkg/fflag/features.go:120

func validateFeatureName(featureName string) error {
	if featureName == "" {
		return ErrFeatureNameEmpty
	}

	if featureName != strings.ToLower(featureName) {
		return ErrFeatureNameCase
	}

	if !featureNameRexp.MatchString(featureName) {
		return ErrFeatureNameInvalid
	}

	return nil
}

func (fr *FeatureRegister) RegisterFeature(feat *Feature) error {
	if err := validateFeatureName(feat.Name); err != nil {
		return fmt.Errorf("feature flag '%s': %w", feat.Name, err)
	}

	if fr.features == nil {
		fr.features = make(map[string]*Feature)
	}

	fr.features[feat.Name] = feat

	return nil
}

func (fr *FeatureRegister) GetFeature(featureName string) (*Feature, error) {
	feat, ok := fr.features[featureName]
	if !ok {
		return feat, ErrFeatureUnknown
	}

	return feat, nil

View on GitHub (pinned to 909b515798)

Solutions

  1. Read the wrapped reason (after the colon) and correct the feature name to satisfy validateFeatureName
  2. Check the Feature literal for an empty or misspelled Name field
  3. Match the naming convention used by existing flags in pkg/fflag (typically lowercase, dashes allowed)
  4. Register flags through the same code path as existing ones to inherit validation-tested names

Example fix

// before
fr.RegisterFeature(&Feature{Name: "Disable HTTP Feature"})
// after
fr.RegisterFeature(&Feature{Name: "disable-http-feature"})
Defensive patterns

Strategy: validation

Validate before calling

var nameRe = regexp.MustCompile(`^[a-z0-9]+(-[a-z0-9]+)*$`)
if !nameRe.MatchString(feat.Name) {
    return fmt.Errorf("invalid feature name %q", feat.Name)
}

Try / catch

if err := fr.RegisterFeature(feat); err != nil {
    var reason string
    if _, werr := fmt.Sscanf(err.Error(), "feature flag '%[1]s': %s", &reason); werr != nil {
        reason = err.Error()
    }
    return fmt.Errorf("bad feature flag registration: %s", reason)
}

Prevention

When it happens

Trigger: Calling RegisterFeature with a Feature whose Name is empty, contains characters outside the allowed set, or otherwise violates the naming rules enforced by validateFeatureName.

Common situations: Typo in a newly registered feature flag name (spaces, uppercase, trailing dash); a nil/empty Name field after constructing Feature programmatically.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


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