{"record":{"id":"f01d7eab53809763","repo":"micro/go-micro","slug":"failed-to-delete-data","errorCode":null,"errorMessage":"Failed to delete data","messagePattern":"Failed to delete data","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"store/nats-js-kv/nats.go","lineNumber":284,"sourceCode":"\t}\n\n\tif opt.Table == \"DELETE_BUCKET\" {\n\t\tn.buckets.Del(key)\n\n\t\tif err := n.js.DeleteKeyValue(key); err != nil {\n\t\t\treturn errors.Wrap(err, \"Failed to delete bucket\")\n\t\t}\n\n\t\treturn nil\n\t}\n\n\tstore, ok := n.buckets.Get(opt.Database)\n\tif !ok {\n\t\treturn ErrBucketNotFound\n\t}\n\n\tif err := store.Delete(n.NatsKey(opt.Table, key)); err != nil {\n\t\treturn errors.Wrap(err, \"Failed to delete data\")\n\t}\n\n\treturn nil\n}\n\n// List returns any keys that match, or an empty list with no error if none matched.\nfunc (n *natsStore) List(opts ...store.ListOption) ([]string, error) {\n\tif err := n.initConn(); err != nil {\n\t\treturn nil, err\n\t}\n\n\topt := store.ListOptions{}\n\tfor _, o := range opts {\n\t\to(&opt)\n\t}\n\n\tif opt.Database == \"\" {\n\t\topt.Database = n.opts.Database","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/store/nats-js-kv/nats.go#L266-L302","documentation":"Returned by Delete when the KV view's Delete of a single key fails, wrapped as \"Failed to delete data\". The bucket was found in the local cache, but JetStream refused the delete operation on that subject.","triggerScenarios":"Calling Delete(key) when the NATS connection is down, the JetStream stream for the bucket has no leader, or the key name produced by n.NatsKey(opt.Table, key) is invalid or cannot be published as a delete subject.","commonSituations":"Deleting a key right after the NATS server restarted (stale connection); deleting during cluster failover; calling Delete before the bucket was actually created server-side because the local cache was populated from a previous session.","solutions":["Check the wrapped error for connection problems and reinitialize/reconnect the store before retrying","Verify the bucket stream is healthy and has a leader ('nats stream info KV_<bucket>')","Validate the key/table combination contains only valid NATS key characters","Treat nats.ErrKeyNotFound-style errors as success if deletes should be idempotent"],"exampleFix":"// before\nif err := st.Delete(key); err != nil { return err }\n// after\nif err := st.Delete(key); err != nil {\n    if errors.Is(err, nats.ErrKeyNotFound) { return nil }\n    return err\n}","handlingStrategy":"retry","validationCode":"// ensure store is initialized and key is valid\nif err := st.Init(); err != nil { return err }\nif strings.ContainsAny(key, \" \") || key == \"\" {\n    return fmt.Errorf(\"invalid key %q\", key)\n}","typeGuard":null,"tryCatchPattern":"if err := st.Delete(key); err != nil {\n    if strings.Contains(err.Error(), \"Failed to delete data\") {\n        _ = st.Init() // refresh connection\n        err = st.Delete(key)\n    }\n    return err\n}","preventionTips":["Reinitialize the store after NATS server restarts (watch for disconnect events)","Keep keys within valid NATS subject characters","Treat delete-of-missing-key as success for idempotency","Check stream health (leader election) when deletes fail during failover"],"tags":["nats","jetstream","delete","kv"],"backgroundTag":"kv-delete-failed","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}