{"record":{"id":"0e54a1d706354ab3","repo":"micro/go-micro","slug":"failed-to-list-objects","errorCode":null,"errorMessage":"Failed to list objects","messagePattern":"Failed to list objects","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"store/nats-js-kv/nats.go","lineNumber":445,"sourceCode":"\t}\n\n\tkeys, _, err := n.getKeys(bucket, table, toS(key, prefix), toS(key, suffix))\n\n\treturn keys, err\n}\n\nfunc (n *natsStore) microKeys(bucket nats.KeyValue, table, prefix, suffix string) ([]string, error) {\n\t_, keys, err := n.getKeys(bucket, table, prefix, suffix)\n\n\treturn keys, err\n}\n\nfunc (n *natsStore) getKeys(bucket nats.KeyValue, table string, prefix, suffix string) ([]string, []string, error) {\n\tnames, err := bucket.Keys(nats.IgnoreDeletes())\n\tif errors.Is(err, nats.ErrKeyNotFound) {\n\t\treturn []string{}, []string{}, nil\n\t} else if err != nil {\n\t\treturn []string{}, []string{}, errors.Wrap(err, \"Failed to list objects\")\n\t}\n\n\tnatsKeys := make([]string, 0, len(names))\n\tmicroKeys := make([]string, 0, len(names))\n\n\tfor _, k := range names {\n\t\tmkey, ok := n.MicroKeyFilter(table, k, prefix, suffix)\n\t\tif !ok {\n\t\t\tcontinue\n\t\t}\n\n\t\tnatsKeys = append(natsKeys, k)\n\t\tmicroKeys = append(microKeys, mkey)\n\t}\n\n\treturn natsKeys, microKeys, nil\n}\n","sourceCodeStart":427,"sourceCodeEnd":463,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/store/nats-js-kv/nats.go#L427-L463","documentation":"The NATS JetStream KV store wrapper calls bucket.Keys(nats.IgnoreDeletes()) to enumerate keys in a bucket and wraps any failure (other than ErrKeyNotFound) with 'Failed to list objects'. It means the JetStream KV bucket could not be enumerated — the keys request to the JetStream stream failed. This surfaces when listing table contents via natsKeys/microKeys.","triggerScenarios":"Calling List/Read with a prefix on a store backed by nats-js-kv when the underlying KeyValue bucket's Keys() call fails: bucket/stream deleted, NATS server unavailable, no permission to read the stream, or a JetStream API error/timeout.","commonSituations":"NATS server restarted or bucket dropped while the service holds a stale handle; bucket name changed between config versions; NATS account lacks JetStream read permissions; JetStream temporarily disabled or resource limits (stream limits) exceeded.","solutions":["Verify the NATS server is reachable and JetStream is enabled (jetstream {} in nats-server config).","Check that the KeyValue bucket exists with the configured name (nats kv ls / nats kv info <bucket>).","Confirm the account/credentials have read permissions on the KV stream.","Reconnect or recreate the store so a fresh KeyValue handle is obtained.","Inspect the wrapped cause in the error chain (errors.Unwrap) for the specific JetStream API error."],"exampleFix":"// before\nkv, _ := js.KeyValue(ctx, \"mybucket\") // stale after bucket recreation\nkeys, err := store.List()\n// after\nkv, err := js.KeyValue(ctx, \"mybucket\")\nif errors.Is(err, nats.ErrBucketNotFound) {\n\tkv, err = js.CreateKeyValue(ctx, nats.KeyValueConfig{Bucket: \"mybucket\"})\n}\nkeys, err := store.List()","handlingStrategy":"retry","validationCode":"// before listing\nresp, err := js.AccountInfo(ctx)\nif err != nil || !resp.JetStreamAccountLimits.MaxStreamLimitsExceeded {\n\t// jetstream reachable\n}\n_, err = js.KeyValue(ctx, bucketName)\nif err != nil { // bucket missing/unreachable: recreate or reconfigure store first }\n","typeGuard":"func isKeyListErr(err error) bool {\n\treturn err != nil && !errors.Is(err, nats.ErrKeyNotFound)\n}","tryCatchPattern":"keys, err := store.List()\nif err != nil {\n\tif isTransient(err) { // reconnect nats and retry\n\t\tnc, _ := nats.Connect(url); defer store.Close(); store = newStore(nc)\n\t\treturn store.List()\n\t}\n\treturn err\n}","preventionTips":["Health-check the NATS connection and JetStream availability before store operations.","Ensure the KV bucket is created at startup (CreateKeyValue with IF-missing semantics).","Grant the NATS account read permissions on the KV stream.","Monitor stream limits and server restarts; recreate handles on disconnect callbacks.","Log errors.Unwrap(err) to capture the underlying JetStream API error."],"tags":["nats","jetstream","kv-store","network"],"backgroundTag":"nats-kv-list-failed","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}