{"record":{"id":"00e828fc4a52e816","repo":"micro/go-micro","slug":"failed-to-create-bucket-s","errorCode":null,"errorMessage":"Failed to create bucket (%s)","messagePattern":"Failed to create bucket \\((.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"store/nats-js-kv/nats.go","lineNumber":382,"sourceCode":"\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\n\t} else if err != nil {\n\t\treturn nil, false, errors.Wrap(err, \"Failed to get object from bucket\")\n\t}\n\n\tvar kv KeyValueEnvelope","sourceCodeStart":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/store/nats-js-kv/nats.go#L364-L400","documentation":"Returned by mustGetBucket when the bucket did not exist and js.CreateKeyValue(kv) fails. Creation requires JetStream to add a stream named KV_<bucket> with the configured TTL/storage/description, and any rejection is wrapped here.","triggerScenarios":"During Init() or first Write to a database: bucket name invalid (invalid NATS subject token characters), a stream named KV_<bucket> already exists as a non-KV stream, JetStream storage limits exceeded, JetStream disabled, or the account lacks permissions to add streams.","commonSituations":"Creating a bucket with a name containing spaces or wildcards ('*'/'>' characters are rejected for KV buckets); server account limits (max streams, max bytes) reached; collision with a manually created plain stream of the same name; JetStream memory/file quota exhausted.","solutions":["Validate the bucket name (no spaces or '*'/'>' characters; valid NATS subject tokens)","Check the wrapped error: if it says the stream already exists but isn't a KV view, remove or rename the conflicting stream ('nats stream rm KV_<bucket>')","Raise the account JetStream limits (max_streams/max_bytes) or free existing streams","Ensure JetStream is enabled and the account has permissions to create streams"],"exampleFix":"// before\nmustGetBucketByName(\"my bucket\") // invalid name\n// after\nmustGetBucketByName(\"my-bucket\")","handlingStrategy":"validation","validationCode":"var validBucket = regexp.MustCompile(`^[a-zA-Z0-9_-]+$`)\nif !validBucket.MatchString(bucketName) {\n    return fmt.Errorf(\"invalid bucket name: %q\", bucketName)\n}","typeGuard":null,"tryCatchPattern":"if err := st.Init(); err != nil {\n    if strings.Contains(err.Error(), \"Failed to create bucket\") {\n        return fmt.Errorf(\"cannot create bucket %s: %w\", name, err)\n    }\n    return err\n}","preventionTips":["Restrict bucket names to alphanumerics, '-', '_' (no spaces or '*'/'>' tokens)","Pre-create buckets with explicit KeyValueConfig during deployment instead of on first write","Monitor account JetStream limits (max streams, max bytes)","Ensure no plain (non-KV) stream already uses the KV_<bucket> name"],"tags":["nats","jetstream","bucket","create"],"backgroundTag":"bucket-create-failed","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}