Skip to content

Commit

Permalink
log-client: fix resuming with no matching logs
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinRoy committed Dec 7, 2023
1 parent 3868f38 commit 44e9f26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-dolls-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lightmill/log-client': patch
---

Fix resuming a log when there are no matching logs found.
9 changes: 6 additions & 3 deletions packages/log-client/src/log-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ export class LogClient<ClientLog extends Typed & OptionallyDated = AnyLog> {
.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,
Expand All @@ -177,7 +178,9 @@ export class LogClient<ClientLog extends Typed & OptionallyDated = AnyLog> {
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;
Expand Down

0 comments on commit 44e9f26

Please sign in to comment.