Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ObjectCallback,
UPDATE,
} from './informer.js';
import { KubernetesObject } from './types.js';
import { KubernetesObject, KubernetesListObject } from './types.js';
import { ObjectSerializer } from './serializer.js';
import { Watch } from './watch.js';

Expand Down Expand Up @@ -143,8 +143,14 @@ export class ListWatch<T extends KubernetesObject> implements ObjectCache<T>, In
}
this.callbackCache[CONNECT].forEach((elt: ErrorCallback) => elt(undefined));
if (!this.resourceVersion) {
const promise = this.listFn();
const list = await promise;
let list: KubernetesListObject<T>;
try {
const promise = this.listFn();
list = await promise;
} catch (err) {
this.callbackCache[ERROR].forEach((elt: ErrorCallback) => elt(err));
return;
}
this.objects = deleteItems(this.objects, list.items, this.callbackCache[DELETE].slice());
this.addOrUpdateItems(list.items);
this.resourceVersion = list.metadata!.resourceVersion || '';
Expand Down
21 changes: 21 additions & 0 deletions src/cache_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1460,4 +1460,25 @@ describe('delete items', () => {

strictEqual(await connectPromise, true);
});

it('should correctly handle errors in the initial list', async () => {
const fake = mock.mock(Watch);
const requestErr = Error('request failed');
const listFn: ListPromise<V1Namespace> = function (): Promise<V1NamespaceList> {
return new Promise<V1NamespaceList>((resolve, reject) => {
reject(requestErr);
});
};
const lw = new ListWatch('/some/path', fake, listFn);
let gotErr: Error | null = null;
const errCalled = new Promise<void>((resolve, reject) => {
lw.on('error', (err) => {
gotErr = err;
resolve();
});
});
await lw.start();
await errCalled;
strictEqual(gotErr, requestErr);
});
});
Loading