{"record":{"id":"6efaad8d18a295f6","repo":"micro/go-micro","slug":"addr-nats-subject-must-not-contain-space-charact","errorCode":null,"errorMessage":"addr (nats subject) must not contain space characters","messagePattern":"addr \\(nats subject\\) must not contain space characters","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"transport/nats/nats.go","lineNumber":490,"sourceCode":"\tc, err := opts.Connect()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// in case address has not been specifically set, create a new nats.Inbox()\n\tif addr == server.DefaultAddress {\n\t\taddr = nats.NewInbox()\n\t}\n\n\t// make sure addr subject is not empty\n\tif len(addr) == 0 {\n\t\treturn nil, errors.New(\"addr (nats subject) must not be empty\")\n\t}\n\n\t// since NATS implements a text based protocol, no space characters are\n\t// admitted in the addr (subject name)\n\tif strings.Contains(addr, \" \") {\n\t\treturn nil, errors.New(\"addr (nats subject) must not contain space characters\")\n\t}\n\n\treturn &ntportListener{\n\t\taddr: addr,\n\t\tconn: c,\n\t\texit: make(chan bool, 1),\n\t\tso:   make(map[string]*ntportSocket),\n\t\topts: n.opts,\n\t}, nil\n}\n\nfunc (n *ntport) Init(opts ...transport.Option) error {\n\tconfigure(n, opts...)\n\treturn nil\n}\n\nfunc (n *ntport) Options() transport.Options {\n\treturn n.opts","sourceCodeStart":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/transport/nats/nats.go#L472-L508","documentation":"NATS subjects are whitespace-delimited tokens in NATS's text protocol, so Listen rejects any addr containing a space. This prevents constructing an invalid subscription that the NATS server would refuse or misparse.","triggerScenarios":"Calling transport.Listen(addr) where addr contains a space character, e.g. Listen(\"my topic\") or an address built from a comma/space-joined list like \"topic1, topic2\".","commonSituations":"Human-readable topic names with spaces pasted into config; building a multi-subject string with \", \" separators; trimming failures leaving leading/trailing spaces from env vars.","solutions":["Replace spaces with valid subject tokens, e.g. \"my.topic\" (dots, letters, digits, -_ allowed)","Split multi-topic strings and create one listener per subject","strings.TrimSpace / normalize addresses loaded from env or config before Listen"],"exampleFix":"// before\nlis, err := t.Listen(\"my service events\")\n// after\nlis, err := t.Listen(\"my.service.events\")","handlingStrategy":"validation","validationCode":"func validSubject(addr string) bool {\n\treturn addr != \"\" && !strings.Contains(addr, \" \")\n}\n// if !validSubject(addr) { addr = strings.ReplaceAll(strings.TrimSpace(addr), \" \", \".\") }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize addresses with strings.TrimSpace and replace spaces with dots","Split comma/space-separated multi-topic strings into separate listeners","Use only [A-Za-z0-9._-] tokens for NATS subjects","Add a config-load validation step for all subject values"],"tags":["nats","transport","listen","validation","subject-name"],"backgroundTag":"invalid-subject-name","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}