{"record":{"id":"5eab7e43f0b5a3c9","repo":"micro/go-micro","slug":"failed-to-get-bucket-s","errorCode":null,"errorMessage":"Failed to get bucket (%s)","messagePattern":"Failed to get bucket \\((.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"store/nats-js-kv/nats.go","lineNumber":377,"sourceCode":"func (n *natsStore) mustGetBucketByName(name string) (nats.KeyValue, error) {\n\treturn n.mustGetBucket(&nats.KeyValueConfig{\n\t\tBucket:      name,\n\t\tDescription: n.description,\n\t\tTTL:         n.ttl,\n\t\tStorage:     n.storageType,\n\t})\n}\n\n// mustGetBucket creates a new bucket if it does not exist yet.\nfunc (n *natsStore) mustGetBucket(kv *nats.KeyValueConfig) (nats.KeyValue, error) {\n\tif store, ok := n.buckets.Get(kv.Bucket); ok {\n\t\treturn store, nil\n\t}\n\n\tstore, err := n.js.KeyValue(kv.Bucket)\n\tif err != nil {\n\t\tif !errors.Is(err, nats.ErrBucketNotFound) {\n\t\t\treturn nil, errors.Wrapf(err, \"Failed to get bucket (%s)\", kv.Bucket)\n\t\t}\n\n\t\tstore, err = n.js.CreateKeyValue(kv)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"Failed to create bucket (%s)\", kv.Bucket)\n\t\t}\n\t}\n\n\tn.buckets.Set(kv.Bucket, store)\n\n\treturn store, nil\n}\n\n// getRecord returns the record with the given key from the nats kv store.\nfunc (n *natsStore) getRecord(bucket nats.KeyValue, key string) (*store.Record, bool, error) {\n\tobj, err := bucket.Get(key)\n\tif errors.Is(err, nats.ErrKeyNotFound) {\n\t\treturn nil, false, store.ErrNotFound","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/store/nats-js-kv/nats.go#L359-L395","documentation":"Returned by mustGetBucket (used by Init and mustGetBucketByName) when js.KeyValue(bucket) fails with an error other than nats.ErrBucketNotFound. That lookup failure means JetStream could not be queried about the bucket at all, so the store cannot proceed to create it.","triggerScenarios":"During Init() with preconfigured kvConfigs or on first Write: the JetStream request times out, the connection is broken, the server has JetStream disabled, or the account lacks permission to look up the stream.","commonSituations":"NATS server unreachable right after Connect succeeded (async disconnect); JetStream not enabled; wrong account/credentials limiting stream visibility; short JetStream request timeouts passed via JS options.","solutions":["Verify JetStream is enabled on the server and the account can access streams ('nats stream ls')","Check network/credentials; reconnect and retry Init after fixing the connection","Increase JetStream API request timeout in the nats.JSOpt options if the wrapped error is a timeout","Check server logs for errors about the stream lookup at the time of the failure"],"exampleFix":"// before\nctx = context.WithValue(ctx, jsOptionsKey{}, []nats.JSOpt{nats.MaxWait(50 * time.Millisecond)})\n// after\nctx = context.WithValue(ctx, jsOptionsKey{}, []nats.JSOpt{nats.MaxWait(5 * time.Second)})","handlingStrategy":"validation","validationCode":"nc, _ := nats.Connect(url)\njs, err := nc.JetStream(nats.MaxWait(5 * time.Second))\nif err != nil { return err }\nif _, err := js.AccountInfo(); err != nil {\n    return fmt.Errorf(\"jetstream unavailable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := st.Init(); err != nil {\n    if strings.Contains(err.Error(), \"Failed to get bucket\") {\n        return fmt.Errorf(\"cannot query jetstream; check server/JS health: %w\", err)\n    }\n    return err\n}","preventionTips":["Enable JetStream on the server and verify account access at deploy time","Use a generous JetStream MaxWait in JS options","Verify credentials/account scope allow stream lookups","Health-check the NATS connection before store operations"],"tags":["nats","jetstream","bucket","lookup"],"backgroundTag":"jetstream-bucket-lookup-failed","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}