From 44e9f268890ea296ecacd79ced4636f725fa3c34 Mon Sep 17 00:00:00 2001 From: Quentin Roy Date: Thu, 7 Dec 2023 18:47:58 +0100 Subject: [PATCH] log-client: fix resuming with no matching logs --- .changeset/honest-dolls-smash.md | 5 +++++ packages/log-client/src/log-client.ts | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .changeset/honest-dolls-smash.md diff --git a/.changeset/honest-dolls-smash.md b/.changeset/honest-dolls-smash.md new file mode 100644 index 00000000..8e10df54 --- /dev/null +++ b/.changeset/honest-dolls-smash.md @@ -0,0 +1,5 @@ +--- +'@lightmill/log-client': patch +--- + +Fix resuming a log when there are no matching logs found. diff --git a/packages/log-client/src/log-client.ts b/packages/log-client/src/log-client.ts index f6029e16..a1f99511 100644 --- a/packages/log-client/src/log-client.ts +++ b/packages/log-client/src/log-client.ts @@ -164,8 +164,9 @@ export class LogClient { .filter((l): l is { type: T } & typeof l => resumeAfterLastSet.has(l.type), ) - .reduce((maxLog, log) => - maxLog.lastNumber > log.lastNumber ? maxLog : log, + .reduce( + (maxLog, log) => (maxLog.lastNumber > log.lastNumber ? maxLog : log), + { lastNumber: 0, count: 0, type: null as null | T }, ); await Interface.resumeRun({ apiRoot: this.#apiRoot, @@ -177,7 +178,9 @@ export class LogClient { this.#experimentId = experimentId; this.#runStatus = 'running'; this.#logCount = lastLog.lastNumber; - return { type: lastLog.type, number: lastLog.count }; + return lastLog.type == null + ? null + : { type: lastLog.type, number: lastLog.count }; } catch (err) { this.#runStatus = 'error'; throw err;