Skip to content

v3.0.0

Choose a tag to compare

@aslushnikov aslushnikov released this 23 Apr 14:55
· 9 commits to main since this release
8c1056a

What's Changed

Migration notes

v3.0.0

GitWorktree.create() and GitWorktree.headCommitId()GitWorktree.initialize()

Both removed methods could throw. The replacement GitWorktree.initialize() returns a
discriminated union that forces the caller to handle failure explicitly, and it also
resolves the HEAD commit in the same call.

export type GitWorktreeInitResult =
  | { ok: true; worktree: GitWorktree; commitId: FlakinessReport.CommitId }
  | { ok: false; error: string };

Rewrite the try/catch pattern that wrapped GitWorktree.create() +
worktree.headCommitId() into an ok check.

Before

let worktree: GitWorktree;
let commitId: FK.CommitId;
try {
  worktree = GitWorktree.create(rootDir);
  commitId = worktree.headCommitId();
} catch {
  console.warn('Failed to fetch commit info - is this a git repo?');
  console.error('Report is NOT generated.');
  return;
}

After

const result = GitWorktree.initialize(rootDir);
if (!result.ok) {
  console.warn(`Failed to fetch commit info - is this a git repo? (${result.error})`);
  console.error('Report is NOT generated.');
  return;
}
const { worktree, commitId } = result;

Notes:

  • GitWorktree.initialize() never throws — do not wrap it in try/catch.
  • After the !result.ok early return, TypeScript narrows result.worktree and
    result.commitId to their non-undefined types.
  • result.error is a human-readable string describing which git command failed; log
    it instead of a generic message if you want better diagnostics.

Full Changelog: v2.7.0...v3.0.0