{"record":{"id":"f26f6c67062c9f4a","repo":"nats-io/nats-server","slug":"undefined-message-handler-f26f6c","errorCode":null,"errorMessage":"undefined message handler","messagePattern":"undefined message handler","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/events.go","lineNumber":2867,"sourceCode":"// Create an internal subscription with queue\nfunc (s *Server) sysSubscribeQ(subject, queue string, cb msgHandler) (*subscription, error) {\n\treturn s.systemSubscribe(subject, queue, false, nil, cb)\n}\n\n// Create an internal subscription but do not forward interest.\nfunc (s *Server) sysSubscribeInternal(subject string, cb msgHandler) (*subscription, error) {\n\treturn s.systemSubscribe(subject, _EMPTY_, true, nil, cb)\n}\n\nfunc (s *Server) systemSubscribe(subject, queue string, internalOnly bool, c *client, cb msgHandler) (*subscription, error) {\n\ts.mu.Lock()\n\tif !s.eventsEnabled() {\n\t\ts.mu.Unlock()\n\t\treturn nil, ErrNoSysAccount\n\t}\n\tif cb == nil {\n\t\ts.mu.Unlock()\n\t\treturn nil, fmt.Errorf(\"undefined message handler\")\n\t}\n\tif c == nil {\n\t\tc = s.sys.client\n\t}\n\ttrace := c.trace\n\ts.sys.sid++\n\tsid := strconv.Itoa(s.sys.sid)\n\ts.mu.Unlock()\n\n\t// Now create the subscription\n\tif trace {\n\t\tc.traceInOp(\"SUB\", []byte(subject+\" \"+queue+\" \"+sid))\n\t}\n\n\tvar q []byte\n\tif queue != _EMPTY_ {\n\t\tq = []byte(queue)\n\t}","sourceCodeStart":2849,"sourceCodeEnd":2885,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/events.go#L2849-L2885","documentation":"Returned by the server's internal system request helper when it is invoked with a nil message handler callback while events (system account) are enabled. The library requires a callback to deliver the response of a system request it issues on the caller's behalf.","triggerScenarios":"Calling the internal requestSystemRequest/helper (e.g. s.newResp or equivalent system-request wrapper) with cb == nil while passing a subject to request system info.","commonSituations":"Plugin or forked-server code invoking the server's internal system request API without supplying a handler; refactoring that dropped a callback argument.","solutions":["Provide a non-nil msgHandler callback when issuing the internal system request","Check that events are enabled (eventsEnabled) and system account configured before calling","If a no-op response is acceptable, pass an empty handler function instead of nil"],"exampleFix":"// before\nresp, err := s.requestResponse(subj, nil, nil)\n// after\nresp, err := s.requestResponse(subj, nil, func(_ *subscription, _ *client, _ *Account, _ string, _ string, hdr, msg []byte) {})\n","handlingStrategy":"validation","validationCode":"if cb == nil {\n    return errors.New(\"system request requires a message handler\")\n}","typeGuard":"func handlerProvided(cb sysMsgHandler) bool { return cb != nil }","tryCatchPattern":"resp, err := s.requestSystemRequest(subj, cb)\nif err != nil {\n    if err.Error() == \"undefined message handler\" {\n        // supply a callback and retry\n    }\n    return err\n}","preventionTips":["Always pass a non-nil handler to internal system request helpers","Check eventsEnabled/system account setup before issuing system requests","Review internal API signatures after server upgrades"],"tags":["internal-api","system-account","nil-argument"],"backgroundTag":"nil-callback-argument","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}