{"record":{"id":"de0c72f91b5cae48","repo":"micro/go-micro","slug":"source-not-found-s","errorCode":null,"errorMessage":"source not found: %s","messagePattern":"source not found: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/source/nats/nats.go","lineNumber":40,"sourceCode":"\n// DefaultBucket is the bucket that nats keys will be assumed to have if you\n// haven't specified one.\nvar (\n\tDefaultBucket = \"default\"\n\tDefaultKey    = \"micro_config\"\n)\n\nfunc (n *nats) Read() (*source.ChangeSet, error) {\n\te, err := n.kv.Get(n.key)\n\tif err != nil {\n\t\tif err == natsgo.ErrKeyNotFound {\n\t\t\treturn nil, nil\n\t\t}\n\t\treturn nil, err\n\t}\n\n\tif e.Value() == nil || len(e.Value()) == 0 {\n\t\treturn nil, fmt.Errorf(\"source not found: %s\", n.key)\n\t}\n\n\tcs := &source.ChangeSet{\n\t\tData:      e.Value(),\n\t\tFormat:    n.opts.Encoder.String(),\n\t\tSource:    n.String(),\n\t\tTimestamp: time.Now(),\n\t}\n\tcs.Checksum = cs.Sum()\n\n\treturn cs, nil\n}\n\nfunc (n *nats) Write(cs *source.ChangeSet) error {\n\t_, err := n.kv.Put(n.key, cs.Data)\n\tif err != nil {\n\t\treturn err\n\t}","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/config/source/nats/nats.go#L22-L58","documentation":"The NATS config source reads a key from a JetStream KV bucket. If the key exists but its value is nil or empty, Read returns 'source not found: <key>'. Note that nats.ErrKeyNotFound itself returns (nil, nil), so this error specifically means the key was found but holds no data.","triggerScenarios":"Calling Read (during config load or Sync) when the KV entry for the configured key exists with an empty/nil value — e.g. the key was created empty or someone Put an empty payload.","commonSituations":"Bootstrapping a fresh KV bucket where the config key was never populated; a deploy pipeline writing an empty config file; a typo'd bucket/key combination resolving to an empty placeholder entry.","solutions":["Put non-empty config data into the KV key before loading: nats kv put <bucket> <key> @config.json","Verify the configured bucket/key options (source.WithContext with your key/bucket values) point at the intended entry","Check upstream writers so the key is never written with empty content","Handle the empty-source case in code: fall back to defaults when Read returns this error"],"exampleFix":"// before\nkv.Put(\"micro_config\", []byte{}) // later: source not found: micro_config\n// after\ncfg, _ := os.ReadFile(\"config.json\")\nkv.Put(\"micro_config\", cfg)","handlingStrategy":"validation","validationCode":"entry, err := kv.Get(key)\nif err != nil || entry == nil || len(entry.Value()) == 0 {\n    return errors.New(\"nats config key missing or empty: \" + key)\n}","typeGuard":"func hasConfigValue(kv natsgo.KeyValue, key string) bool {\n    e, err := kv.Get(key)\n    return err == nil && e != nil && len(e.Value()) > 0\n}","tryCatchPattern":null,"preventionTips":["Seed the KV key with valid config before starting services that read it","Validate bucket/key options at construction time","Make CI deploys fail if they would write empty config payloads","Fall back to defaults when a source is empty, and log loudly"],"tags":["config","nats","jetstream","kv","missing-key"],"backgroundTag":"config-source-not-found","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}