{"record":{"id":"f6b98a4a9fefd465","repo":"go-delve/delve","slug":"s-is-not-a-function","errorCode":null,"errorMessage":"%s is not a function","messagePattern":"(.+?) is not a function","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/terminal/starbind/starlark.go","lineNumber":360,"sourceCode":"\t\t}\n\t\t_, err = starlark.Call(thread, fnval, argtuple, nil)\n\t\treturn err\n\t}, allowedPrefixes)\n\treturn nil\n}\n\n// callMain calls the main function in globals, if one was defined.\nfunc (env *Env) callMain(thread *starlark.Thread, globals starlark.StringDict, mainFnName string, args []any) (starlark.Value, error) {\n\tif mainFnName == \"\" {\n\t\treturn starlark.None, nil\n\t}\n\tmainval := globals[mainFnName]\n\tif mainval == nil {\n\t\treturn starlark.None, nil\n\t}\n\tmainfn, ok := mainval.(*starlark.Function)\n\tif !ok {\n\t\treturn starlark.None, fmt.Errorf(\"%s is not a function\", mainFnName)\n\t}\n\tif mainfn.NumParams() != len(args) {\n\t\treturn starlark.None, fmt.Errorf(\"wrong number of arguments for %s\", mainFnName)\n\t}\n\targtuple := make(starlark.Tuple, len(args))\n\tfor i := range args {\n\t\targtuple[i] = env.interfaceToStarlarkValue(args[i])\n\t}\n\treturn starlark.Call(thread, mainfn, argtuple, nil)\n}\n\nfunc isCancelled(thread *starlark.Thread) error {\n\tif ctx, ok := thread.Local(dlvContextName).(context.Context); ok {\n\t\tselect {\n\t\tcase <-ctx.Done():\n\t\t\treturn ctx.Err()\n\t\tdefault:\n\t\t}","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/terminal/starbind/starlark.go#L342-L378","documentation":"callMain looks up the script's global `main` symbol and requires it to be a starlark function. If the global exists but is not a function (e.g. it is a list, dict, string, or number), the executor returns this error instead of attempting to call it. It protects the interpreter from calling a non-callable value.","triggerScenarios":"Running `Execute` on a starlark script that defines a global named `main` bound to a non-function value, e.g. `main = [1,2,3]` or `main = \"run\"`.","commonSituations":"Copy-pasted scripts where a variable was accidentally named `main`, or scripts that renamed their entrypoint but left `main` as a constant/placeholder.","solutions":["Rename the non-function global so `main` is free, or delete it.","Define `main` as a proper starlark function: `def main(arg): ...`.","Check the top of the script for shadowing of `main` after imports."],"exampleFix":"// before (in .star script)\nmain = \"entrypoint\"\n// after\ndef main(args):\n    pass","handlingStrategy":"type-guard","validationCode":"# starlark: ensure main is a function before execute\nif main == None:\n    fail('main not defined')\n# must be defined with def main(...):","typeGuard":"// starlark-side guard is not expressible in Go; ensure in script:\n// def main(args):  # 'def' guarantees a *starlark.Function\n//     pass","tryCatchPattern":"err := env.Execute(...)\nif err != nil && strings.Contains(err.Error(), \"is not a function\") {\n    return fmt.Errorf(\"script: global 'main' must be defined with def: %w\", err)\n}","preventionTips":["Never assign other values to a variable named main","Define the entrypoint with def, not assignment","Grep scripts for '^main = ' before running"],"tags":["go","starlark","type-mismatch","scripting"],"backgroundTag":"entrypoint-not-callable","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}