{"record":{"id":"84029e9f78d7e72d","repo":"micro/go-micro","slug":"addr-nats-subject-must-not-be-empty","errorCode":null,"errorMessage":"addr (nats subject) must not be empty","messagePattern":"addr \\(nats subject\\) must not be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"transport/nats/nats.go","lineNumber":484,"sourceCode":"\n\t// secure might not be set\n\tif n.opts.TLSConfig != nil {\n\t\topts.Secure = true\n\t}\n\n\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 {","sourceCodeStart":466,"sourceCodeEnd":502,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/transport/nats/nats.go#L466-L502","documentation":"Listen validates the NATS subject (addr) before creating the listener. If the address string is empty (and was not replaced by an auto-generated NATS inbox), Listen refuses to start since NATS cannot subscribe to a blank subject. Note that transport.DefaultAddress is pre-replaced with a random inbox, so the error only fires for explicitly empty addresses.","triggerScenarios":"Calling transport.Listen(\":\", ... variants that resolve to \"\" ) — specifically passing addr == \"\" not equal to server.DefaultAddress, e.g. Listen(\"\", ...) or an empty option value that bypasses the DefaultAddress substitution.","commonSituations":"Config file/env var for the service address left empty; template variable not expanded; passing DefaultAddress sentinel through a layer that already replaced it with \"\"; copy-paste removing the subject.","solutions":["Pass a valid NATS subject, e.g. transport.Listen(\"my.subject\", ...)","Use the DefaultAddress sentinel (\"\"/0.0.0.0 style) so Listen generates a random inbox via nats.NewInbox()","Fix the configuration source (env var/flag) so the subject is populated before Listen"],"exampleFix":"// before\nlis, err := t.Listen(\"\")\n// after\nlis, err := t.Listen(\"micro.service.topic\")\n// or for a random inbox:\nlis, err := t.Listen(server.DefaultAddress)","handlingStrategy":"validation","validationCode":"func validateSubject(addr string) error {\n\tif addr == \"\" {\n\t\treturn errors.New(\"nats subject must not be empty\")\n\t}\n\treturn nil\n}\n// if err := validateSubject(addr); err != nil { addr = server.DefaultAddress }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass empty strings as transport.Listen addresses; use server.DefaultAddress for a random inbox","Centralize subject constants instead of reading raw env values","Fail fast at config load if the address is empty"],"tags":["nats","transport","listen","configuration","validation"],"backgroundTag":"empty-address-config","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}