{"record":{"id":"b2fdea7d27ca9554","repo":"micro/go-micro","slug":"errmissingtopic","errorCode":"ErrMissingTopic","errorMessage":"missing topic","messagePattern":"missing topic","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"events/events.go","lineNumber":19,"sourceCode":"// Package events is for event streaming and storage\npackage events\n\nimport (\n\t\"encoding/json\"\n\t\"errors\"\n\t\"time\"\n)\n\nvar (\n\t// DefaultStream is the default events stream implementation\n\tDefaultStream Stream\n\t// DefaultStore is the default events store implementation\n\tDefaultStore Store\n)\n\nvar (\n\t// ErrMissingTopic is returned if a blank topic was provided to publish\n\tErrMissingTopic = errors.New(\"missing topic\")\n\t// ErrEncodingMessage is returned from publish if there was an error encoding the message option\n\tErrEncodingMessage = errors.New(\"error encoding message\")\n)\n\n// Stream is an event streaming interface\ntype Stream interface {\n\tPublish(topic string, msg interface{}, opts ...PublishOption) error\n\tConsume(topic string, opts ...ConsumeOption) (<-chan Event, error)\n}\n\n// Store is an event store interface\ntype Store interface {\n\tRead(topic string, opts ...ReadOption) ([]*Event, error)\n\tWrite(event *Event, opts ...WriteOption) error\n}\n\ntype AckFunc func() error\ntype NackFunc func() error","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/events/events.go#L1-L37","documentation":"ErrMissingTopic is the sentinel error returned by the events package when an empty topic string is supplied. Topics identify event streams, so publish, consume, and read all require a non-blank topic to route the message.","triggerScenarios":"Calling Stream.Publish(\"\", msg), Stream.Consume(\"\", ...), or Store.Read(topic=\"\") with a topic variable that is the empty string (unset config value, uninitialized struct field).","commonSituations":"A topic configured via env var/config file that isn't set in one environment; a struct field of topic names zero-valued; string interpolation that yields an empty topic (e.g. fmt.Sprintf with empty parts).","solutions":["Check for the sentinel before use: if errors.Is(err, events.ErrMissingTopic), log which call site supplied the blank topic.","Validate topic non-empty before calling Publish/Consume and fail fast with the topic's config key name in the message.","Provide a default topic in configuration or derive it from the service name when unset.","Fix upstream wiring so the topic variable is populated (env var, config file, constructor argument)."],"exampleFix":"// before\ntopic := os.Getenv(\"EVENTS_TOPIC\")\nstream.Publish(topic, msg) // ErrMissingTopic if unset\n// after\ntopic := os.Getenv(\"EVENTS_TOPIC\")\nif topic == \"\" {\n    topic = \"default-events\"\n}\nstream.Publish(topic, msg)","handlingStrategy":"validation","validationCode":"if topic == \"\" {\n    return events.ErrMissingTopic\n}","typeGuard":null,"tryCatchPattern":"if err := stream.Publish(topic, msg); err != nil {\n    if errors.Is(err, events.ErrMissingTopic) {\n        return fmt.Errorf(\"publish: topic not configured: %w\", err)\n    }\n    return err\n}","preventionTips":["Validate topic at config load time, not at publish time","Provide sensible default topics derived from service name","Fail fast on empty env/config values feeding topics"],"tags":["events","pubsub","validation","missing-topic"],"backgroundTag":"missing-topic","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}