{"record":{"id":"3bc1aa7426cc3b73","repo":"micro/go-micro","slug":"subscribe-to-s-w","errorCode":null,"errorMessage":"subscribe to %s: %w","messagePattern":"subscribe to (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"flow/flow.go","lineNumber":152,"sourceCode":"\t\tmodelOpts = append(modelOpts, ai.WithTools(f.toolSet))\n\n\t\tf.model = ai.New(f.opts.Provider, modelOpts...)\n\t\tif f.model == nil {\n\t\t\treturn fmt.Errorf(\"unknown provider: %s\", f.opts.Provider)\n\t\t}\n\t}\n\n\tif f.opts.TriggerTopic != \"\" {\n\t\tsub, err := br.Subscribe(f.opts.TriggerTopic, func(p broker.Event) error {\n\t\t\tdata := string(p.Message().Body)\n\t\t\tctx := ai.WithRunInfo(context.Background(), ai.RunInfo{Dispatch: \"broker\", Trigger: f.opts.TriggerTopic})\n\t\t\tif err := f.Execute(ctx, data); err != nil {\n\t\t\t\tf.log.Logf(logger.ErrorLevel, \"Flow %s failed: %v\", f.name, err)\n\t\t\t}\n\t\t\treturn nil\n\t\t})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"subscribe to %s: %w\", f.opts.TriggerTopic, err)\n\t\t}\n\t\tf.sub = sub\n\t\tf.log.Logf(logger.InfoLevel, \"Flow %s subscribed to %s\", f.name, f.opts.TriggerTopic)\n\n\t\t// Announce the flow in the registry so it's discoverable like a\n\t\t// service or agent (e.g. `micro flow list`). This is liveness only:\n\t\t// Stop deregisters it. Durable run history lives in the store.\n\t\tf.registration = &registry.Service{\n\t\t\tName:    f.name,\n\t\t\tVersion: \"latest\",\n\t\t\tMetadata: map[string]string{\n\t\t\t\t\"type\":    \"flow\",\n\t\t\t\t\"trigger\": f.opts.TriggerTopic,\n\t\t\t\t\"steps\":   strconv.Itoa(len(f.opts.Steps)),\n\t\t\t},\n\t\t\tNodes: []*registry.Node{{\n\t\t\t\tId:       f.name + \"-\" + uuid.New().String()[:8],\n\t\t\t\tAddress:  \"flow://\" + f.name,","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/flow/flow.go#L134-L170","documentation":"Flow registration failed because the broker subscription to the flow's trigger topic returned an error. The wrapped error (%w) carries the broker-specific cause — typically a broker not configured, connection failure, or invalid topic.","triggerScenarios":"Calling Register on a flow with TriggerTopic set when br.Subscribe fails — e.g. no broker initialized in the micro service, broker connection down, or invalid/empty topic syntax.","commonSituations":"Forgetting micro broker init in standalone tests; NATS/Redis broker unreachable at startup; topic names with illegal characters; permissions rejecting the subscription.","solutions":["Ensure a broker is initialized and connected before Register (broker.Init / service Init).","Verify broker connectivity (broker.Connect) and inspect the wrapped error for dial failures.","Validate the TriggerTopic string (no spaces/illegal chars, non-empty).","Check broker-side ACLs/permissions if using an authenticated broker."],"exampleFix":"// before\nf.Register(ctx) // broker never initialized\n// after\nbr.Init(broker.Backend(natsbroker.NewBroker(natsbroker.Addrs(\"nats://localhost:4222\"))))\nbr.Connect(ctx)\nf.Register(ctx)","handlingStrategy":"retry","validationCode":"if err := br.Connect(ctx); err != nil {\n\treturn fmt.Errorf(\"broker not connected before flow Register: %w\", err)\n}","typeGuard":"func brokerReady(br broker.Broker) bool { return br != nil && br.String() != \"\" }","tryCatchPattern":"if err := f.Register(ctx); err != nil {\n\tif strings.Contains(err.Error(), \"subscribe to\") {\n\t\ttime.Sleep(2 * time.Second)\n\t\treturn f.Register(ctx) // broker may still be connecting\n\t}\n\treturn err\n}","preventionTips":["Always init and connect the broker before registering flows.","Use service-level bootstrap ordering (broker -> flows -> serve).","Validate trigger topic names at config load time."],"tags":["flow","broker","subscription","network"],"backgroundTag":"broker-subscribe-failed","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}