{"record":{"id":"f0188d15040a12f0","repo":"nats-io/nats-server","slug":"processpub-parse-error-q","errorCode":null,"errorMessage":"processPub Parse Error: %q","messagePattern":"processPub Parse Error: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/client.go","lineNumber":2987,"sourceCode":"\t}\n\tif start >= 0 {\n\t\targs = append(args, arg[start:])\n\t}\n\n\tc.pa.arg = arg\n\tswitch len(args) {\n\tcase 2:\n\t\tc.pa.subject = args[0]\n\t\tc.pa.reply = nil\n\t\tc.pa.size = parseSize(args[1])\n\t\tc.pa.szb = args[1]\n\tcase 3:\n\t\tc.pa.subject = args[0]\n\t\tc.pa.reply = args[1]\n\t\tc.pa.size = parseSize(args[2])\n\t\tc.pa.szb = args[2]\n\tdefault:\n\t\treturn fmt.Errorf(\"processPub Parse Error: %q\", arg)\n\t}\n\t// If number overruns an int64, parseSize() will have returned a negative value\n\tif c.pa.size < 0 {\n\t\treturn fmt.Errorf(\"processPub Bad or Missing Size: %q\", arg)\n\t}\n\tmaxPayload := atomic.LoadInt32(&c.mpay)\n\t// Use int64() to avoid int32 overrun...\n\tif maxPayload != jwt.NoLimit && int64(c.pa.size) > int64(maxPayload) {\n\t\tc.maxPayloadViolation(c.pa.size, maxPayload)\n\t\treturn ErrMaxPayload\n\t}\n\tif c.opts.Pedantic && !IsValidLiteralSubject(bytesToString(c.pa.subject)) {\n\t\tc.sendErr(\"Invalid Publish Subject\")\n\t}\n\treturn nil\n}\n\nfunc splitArg(arg []byte) [][]byte {","sourceCodeStart":2969,"sourceCodeEnd":3005,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/client.go#L2969-L3005","documentation":"The PUB protocol operation could not be tokenized correctly. processPub expects 3 args (subject, reply, size) for pub with reply or 2 args (subject, size) for plain pub; any other arg count hits the default branch and returns this parse error, closing the connection.","triggerScenarios":"Client sends `PUB` with the wrong number of space-separated tokens, e.g. `PUB subject` (missing size) or `PUB subject reply size extra`, so the switch on len(args) falls through to default.","commonSituations":"Hand-crafted protocol frames in scripts/tests, broken telnet-style clients, a proxy splitting or merging protocol lines, client library bug after a protocol change.","solutions":["Emit PUB with exactly `PUB <subject> <size>` or `PUB <subject> <reply> <size>` followed by CRLF and the payload","Fix or upgrade the client library generating the frames","Verify no intermediary proxy/middlebox alters whitespace or line framing"],"exampleFix":"// before\nPUB subject\n// after\nPUB subject 5\nhello","handlingStrategy":"validation","validationCode":"if reply == \"\" {\n    frame = fmt.Sprintf(\"PUB %s %d\\r\\n\", subject, len(payload))\n} else {\n    frame = fmt.Sprintf(\"PUB %s %s %d\\r\\n\", subject, reply, len(payload))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only send 2 or 3 space-separated tokens after PUB","Ensure subject/reply contain no embedded spaces","Prefer the official NATS client over telnet/scripted frames"],"tags":["protocol","parsing","nats"],"backgroundTag":"nats-protocol-parse-error","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}