{"record":{"id":"c70d33fc1fed426a","repo":"nats-io/nats-server","slug":"subject-q-is-malformed","errorCode":null,"errorMessage":"subject %q is malformed","messagePattern":"subject %q is malformed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/events.go","lineNumber":1364,"sourceCode":"\t\tcase \"STATSZ\":\n\t\t\th = s.noInlineCallbackStatsz(req)\n\t\tdefault:\n\t\t\th = s.noInlineCallback(req)\n\t\t}\n\t\tsubject = fmt.Sprintf(serverDirectReqSubj, s.info.ID, name)\n\t\tif _, err := s.sysSubscribe(subject, h); err != nil {\n\t\t\ts.Errorf(\"Error setting up internal tracking: %v\", err)\n\t\t\treturn\n\t\t}\n\t\tsubject = fmt.Sprintf(serverPingReqSubj, name)\n\t\tif _, err := s.sysSubscribe(subject, h); err != nil {\n\t\t\ts.Errorf(\"Error setting up internal tracking: %v\", err)\n\t\t\treturn\n\t\t}\n\t}\n\textractAccount := func(subject string) (string, error) {\n\t\tif tk := strings.Split(subject, tsep); len(tk) != accReqTokens {\n\t\t\treturn _EMPTY_, fmt.Errorf(\"subject %q is malformed\", subject)\n\t\t} else {\n\t\t\treturn tk[accReqAccIndex], nil\n\t\t}\n\t}\n\tmonAccSrvc := map[string]sysMsgHandler{\n\t\t\"SUBSZ\": func(sub *subscription, c *client, _ *Account, subject, reply string, hdr, msg []byte) {\n\t\t\toptz := &SubszEventOptions{}\n\t\t\ts.zReq(c, reply, hdr, msg, &optz.EventFilterOptions, optz, func() (any, error) {\n\t\t\t\tif acc, err := extractAccount(subject); err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t} else {\n\t\t\t\t\toptz.SubszOptions.Subscriptions = true\n\t\t\t\t\toptz.SubszOptions.Account = acc\n\t\t\t\t\treturn s.Subsz(&optz.SubszOptions)\n\t\t\t\t}\n\t\t\t})\n\t\t},\n\t\t\"CONNZ\": func(sub *subscription, c *client, _ *Account, subject, reply string, hdr, msg []byte) {","sourceCodeStart":1346,"sourceCodeEnd":1382,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/events.go#L1346-L1382","documentation":"This internal error is produced by the monitoring/system-account service setup in events.go when a request subject received on an internal system service does not tokenize into the expected number of tokens (accReqTokens, e.g. '$SYS.REQ.ACCOUNT.<account>.<endpoint>'). The library throws it to skip a malformed system request it cannot attribute to an account.","triggerScenarios":"A message published to a $SYS.REQ.ACCOUNT.* service subject with the wrong number of dot-separated tokens, so extractAccount's strings.Split does not yield accReqTokens tokens.","commonSituations":"Custom tooling publishing handcrafted $SYS request subjects; version mismatches where internal system subject schemas changed between server versions; typos in monitoring scripts.","solutions":["Use the canonical system request subject format, e.g. '$SYS.REQ.ACCOUNT.<account-id>.<ENDPOINT>' with all tokens present","Prefer the server's provided request helpers/monitoring client rather than hand-building subjects","Upgrade client monitoring tools to match the server version's system API subjects"],"exampleFix":"// before\nsub := \"$SYS.REQ.ACCOUNT.SUBSZ\" // missing account token\n// after\nsub := \"$SYS.REQ.ACCOUNT.\" + accID + \".SUBSZ\"","handlingStrategy":"type-guard","validationCode":"func validSysReqSubject(subj string) bool {\n    return strings.HasPrefix(subj, \"$SYS.REQ.ACCOUNT.\") && len(strings.Split(subj, \".\")) == 6\n}","typeGuard":"func isMalformedSubjectErr(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"is malformed\")\n}","tryCatchPattern":"acc, err := extractAccount(subject)\nif err != nil {\n    // log and drop malformed system request\n    return\n}","preventionTips":["Use published system request subject constants/helpers, not hand-built strings","Match the token count expected by your server version's system API","Keep monitoring tools version-aligned with the server"],"tags":["monitoring","system-account","subject-format"],"backgroundTag":"malformed-system-subject","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}