Skip to content

Commit

Permalink
[FIX] stream names lister streams fails with NPE when no streams are …
Browse files Browse the repository at this point in the history
…defined
  • Loading branch information
aricart committed Nov 14, 2023
1 parent 9b25658 commit 9da08fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 8 additions & 3 deletions jetstream/jslister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ export class ListerImpl<T> implements Lister<T>, AsyncIterable<T> {
this.pageInfo = r as ApiPaged;
// offsets are reported in total, so need to count
// all the entries returned
this.offset += this.countResponse(r as ApiResponse);
const count = this.countResponse(r as ApiResponse);
if(count === 0) {
// we are done if we get a null set of infos
return [];
}
this.offset += count;
const a = this.filter(r);
return a;
} catch (err) {
Expand All @@ -92,9 +97,9 @@ export class ListerImpl<T> implements Lister<T>, AsyncIterable<T> {
switch (r?.type) {
case "io.nats.jetstream.api.v1.stream_names_response":
case "io.nats.jetstream.api.v1.stream_list_response":
return (r as StreamListResponse).streams.length;
return (r as StreamListResponse).streams?.length || 0;
case "io.nats.jetstream.api.v1.consumer_list_response":
return (r as ConsumerListResponse).consumers.length;
return (r as ConsumerListResponse).consumers?.length || 0;
default:
console.error(
`jslister.ts: unknown API response for paged output: ${r?.type}`,
Expand Down
10 changes: 10 additions & 0 deletions jetstream/tests/jsm_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ Deno.test("jsm - no stream lister is empty", async () => {
await cleanup(ns, nc);
});

Deno.test("jsm - stream names is empty", async () => {
const { ns, nc } = await setup(jetstreamServerConf({}, true));
const jsm = await nc.jetstreamManager();
const names = await jsm.streams.names().next();
assertEquals(names.length, 0);
await cleanup(ns, nc);
});



Deno.test("jsm - lister after empty, empty", async () => {
const { ns, nc } = await setup(jetstreamServerConf({}, true));
const jsm = await nc.jetstreamManager();
Expand Down

0 comments on commit 9da08fe

Please sign in to comment.