{"record":{"id":"854b0ec219509171","repo":"crowdsecurity/crowdsec","slug":"s-w","errorCode":null,"errorMessage":"%s: %w","messagePattern":"%s: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/alertcontext/config.go","lineNumber":64,"sourceCode":"\n\treturn nil\n}\n\n// addContextFromItem merges the context from an item into the context to send to the console.\nfunc addContextFromItem(toSend map[string][]string, item *cwhub.Item) error {\n\tfilePath := item.State.LocalPath\n\tlog.Tracef(\"loading console context from %s\", filePath)\n\n\tcontent, err := os.ReadFile(filePath)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\twrapper := &HubItemWrapper{}\n\n\terr = yaml.Unmarshal(content, wrapper)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%s: %w\", filePath, err)\n\t}\n\n\terr = mergeContext(toSend, wrapper.Context)\n\tif err != nil {\n\t\t// having an empty hub item deserves an error\n\t\tlog.Errorf(\"while merging context from %s: %s. Note that context data should be under the 'context:' key, the top-level is metadata.\", filePath, err)\n\t}\n\n\treturn nil\n}\n\n// addContextFromFile merges the context from a file into the context to send to the console.\nfunc addContextFromFile(toSend map[string][]string, filePath string) error {\n\tlog.Tracef(\"loading console context from %s\", filePath)\n\n\tcontent, err := os.ReadFile(filePath)\n\tif err != nil {\n\t\treturn err","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/alertcontext/config.go#L46-L82","documentation":"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.","triggerScenarios":"Thrown at pkg/alertcontext/config.go:64 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the YAML in the context item file named in the message","Reinstall/update the context item via cscli hub update / cscli contexts"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}