{"record":{"id":"5fd3863731666fae","repo":"crowdsecurity/crowdsec","slug":"basename-missing-argument","errorCode":null,"errorMessage":"basename: missing argument","messagePattern":"basename: missing argument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/helpers.go","lineNumber":12,"sourceCode":"package hubtest\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"path/filepath\"\n)\n\nfunc basename(params ...any) (any, error) {\n\t// keep nilaway happy\n\tif len(params) == 0 || params[0] == nil {\n\t\treturn \"\", errors.New(\"basename: missing argument\")\n\t}\n\n\t// keep forcetypeassert happy\n\ts, ok := params[0].(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"basename: want string, got %T\", params[0])\n\t}\n\n\treturn filepath.Base(s), nil\n}\n","sourceCodeStart":1,"sourceCodeEnd":23,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/helpers.go#L1-L23","documentation":"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.","triggerScenarios":"Invoking basename() with zero params in an expr expression inside a hub test file, or basename(nil).","commonSituations":"Hand-edited test YAML where the basename() expression lost its argument; dynamic expression evaluation where the variable feeding basename was nil.","solutions":["Pass a string argument: basename('some/file/name.yaml')","Ensure the variable inside basename(...) is populated before evaluation","Check the expr expression syntax in the hub test file for a dropped parameter"],"exampleFix":"// before\nbasename()\n// after\nbasename(evt.Parsed.filename)","handlingStrategy":"validation","validationCode":"if arg == nil || arg == \"\" { skip := true } else { out, _ := basename(arg) }","typeGuard":"func safeBasename(params ...any) (any, error) { if len(params) == 0 || params[0] == nil { return \"\", errors.New(\"basename needs a string argument\") }; return basename(params...) }","tryCatchPattern":"out, err := basename(input)\nif err != nil { log.Warnf(\"basename failed: %v\", err) }","preventionTips":["Always pass one non-nil string argument to basename()","Check expr expressions in hub test YAML after manual edits","Validate upstream variables are populated before interpolation"],"tags":["go","expr","helpers","argument-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}