{"record":{"id":"cea751f683722984","repo":"grafana/k6","slug":"exported-identifier-s-must-be-a-function","errorCode":null,"errorMessage":"exported identifier %s must be a function","messagePattern":"exported identifier (.+?) must be a function","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/runner.go","lineNumber":486,"sourceCode":"\t\thandleSummaryData = summaryData\n\t}\n\n\treturn noColor, enableColors, newMachineReadableSummary, summaryCode, summaryData, handleSummaryData, err\n}\n\nfunc runUserProvidedHandleSummaryCallback(\n\tsummaryCtx context.Context,\n\tvu *VU,\n\thandleSummaryData sobek.Value,\n) (sobek.Value, error) {\n\tfn := vu.getExported(consts.HandleSummaryFn)\n\tif fn == nil {\n\t\treturn sobek.Undefined(), nil\n\t}\n\n\thandleSummaryFn, ok := sobek.AssertFunction(fn)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"exported identifier %s must be a function\", consts.HandleSummaryFn)\n\t}\n\n\tcallbackResult, _, _, err := vu.runFn(summaryCtx, false, handleSummaryFn, nil, handleSummaryData)\n\tif err != nil {\n\t\terrText, fields := errext.Format(err)\n\t\tvu.Runner.preInitState.Logger.WithFields(fields).Error(errText)\n\t}\n\n\t// In case of error, we only want to log it\n\t// but still proceed with the built-in summary handler, so we return nil.\n\treturn callbackResult, nil\n}\n\nfunc prepareHandleWrapperArgs(\n\tvu *VU,\n\tnoColor, enableColors, newMachineReadableSummary bool,\n\tcallbackResult, handleSummaryData, summaryData sobek.Value,\n) []sobek.Value {","sourceCodeStart":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/runner.go#L468-L504","documentation":"The script exports a `handleSummary` identifier, but its value is not callable (a number, string, object, etc.). k6 checks the export with AssertFunction after confirming it exists; anything that is not a function is rejected before the summary machinery runs. Omitting the export entirely is fine — only a non-function export triggers this.","triggerScenarios":"Thrown at internal/js/runner.go:486 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Export handleSummary as a function: export function handleSummary(data) { ... }","Remove the export if a default summary is wanted","Do not assign constants or objects to handleSummary; the exported binding must be a callable"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}