{"record":{"id":"f9a2c6ed93036779","repo":"apache/beam","slug":"value-v-is-not-a-function","errorCode":null,"errorMessage":"value %v is not a function","messagePattern":"value (.+?) is not a function","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/functions.go","lineNumber":33,"sourceCode":"\npackage reflectx\n\nimport (\n\t\"fmt\"\n\t\"reflect\"\n\t\"runtime\"\n\t\"unsafe\"\n)\n\n// TODO(herohde) 7/21/2017: we rely on the happy fact that the function name is\n// also the symbol name. We should perhaps make that connection explicit.\n\n// FunctionName returns the symbol name of a function. It panics if the given\n// value is not a function.\nfunc FunctionName(fn any) string {\n\tval := reflect.ValueOf(fn)\n\tif val.Kind() != reflect.Func {\n\t\tpanic(fmt.Sprintf(\"value %v is not a function\", fn))\n\t}\n\n\treturn runtime.FuncForPC(uintptr(val.Pointer())).Name()\n}\n\n// LoadFunction loads a function from a pointer and type. Assumes the pointer\n// points to a valid function implementation.\nfunc LoadFunction(ptr uintptr, t reflect.Type) any {\n\tv := reflect.New(t).Elem()\n\tp := new(uintptr)\n\t*p = ptr\n\t*(*unsafe.Pointer)(unsafe.Pointer(v.Addr().Pointer())) = unsafe.Pointer(p)\n\treturn v.Interface()\n}\n","sourceCodeStart":15,"sourceCodeEnd":48,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/functions.go#L15-L48","documentation":"reflectx.FunctionName returns the runtime symbol name of a function value. It panics when the argument's reflect.Kind is not reflect.Func, since a non-function value has no PC to look up a symbol name for.","triggerScenarios":"Calling reflectx.FunctionName with a non-func value such as a string, int, nil, struct, or method value wrapper that is not a Func.","commonSituations":"Registering functions in reflectx's function registry where a variable meant to hold a function is uninitialized or holds the wrong type; test helpers like TestFunctionName feeding non-function values.","solutions":["Ensure the value passed to FunctionName is actually a func before calling it.","Guard with reflect.ValueOf(v).Kind() == reflect.Func.","Fix variable initialization so the correct function reference is assigned instead of a zero value."],"exampleFix":"// before\nname := reflectx.FunctionName(myVar) // myVar is a string\n// after\nif reflect.ValueOf(myVar).Kind() == reflect.Func {\n    name := reflectx.FunctionName(myVar)\n}","handlingStrategy":"type-guard","validationCode":"if reflect.ValueOf(fn).Kind() != reflect.Func {\n    return fmt.Errorf(\"FunctionName requires a func, got %T\", fn)\n}","typeGuard":"func isFunction(v any) bool {\n    return v != nil && reflect.ValueOf(v).Kind() == reflect.Func\n}","tryCatchPattern":"func safeFunctionName(fn any) (name string, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"not a function: %v\", r)\n        }\n    }()\n    return reflectx.FunctionName(fn), nil\n}","preventionTips":["Type function-registry inputs as func or a named func type in your API.","Check for nil/zero-valued variables before passing them as functions."],"tags":["go","reflection","invalid-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}