crowdsecurity/crowdsec · error

%s: %w

Error message

%s: %w

What it means

addContextFromItem fails to unmarshal a hub context item's yaml file, wrapping the parse error with the file path. The item's local yaml (from hub item State.LocalPath) is malformed or has unexpected fields.

Source

Thrown at pkg/alertcontext/config.go:64

	return nil
}

// addContextFromItem merges the context from an item into the context to send to the console.
func addContextFromItem(toSend map[string][]string, item *cwhub.Item) error {
	filePath := item.State.LocalPath
	log.Tracef("loading console context from %s", filePath)

	content, err := os.ReadFile(filePath)
	if err != nil {
		return err
	}

	wrapper := &HubItemWrapper{}

	err = yaml.Unmarshal(content, wrapper)
	if err != nil {
		return fmt.Errorf("%s: %w", filePath, err)
	}

	err = mergeContext(toSend, wrapper.Context)
	if err != nil {
		// having an empty hub item deserves an error
		log.Errorf("while merging context from %s: %s. Note that context data should be under the 'context:' key, the top-level is metadata.", filePath, err)
	}

	return nil
}

// addContextFromFile merges the context from a file into the context to send to the console.
func addContextFromFile(toSend map[string][]string, filePath string) error {
	log.Tracef("loading console context from %s", filePath)

	content, err := os.ReadFile(filePath)
	if err != nil {
		return err

View on GitHub (pinned to 909b515798)

Solutions

  1. Fix the YAML in the context item file named in the message
  2. Reinstall/update the context item via cscli hub update / cscli contexts
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/alertcontext/config.go:64 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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