From fe133eab99624d91183b2121f6641789dc1032fd Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Tue, 31 Mar 2026 23:22:38 -0700 Subject: [PATCH] fix: improve error handling in getCommitsSinceLastTag - Add nested try-catch to handle git log failures - Return empty array if all git attempts fail - Add warning message when commit history cannot be retrieved --- scripts/bump-version.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/bump-version.js b/scripts/bump-version.js index 6fc2f65..80be566 100755 --- a/scripts/bump-version.js +++ b/scripts/bump-version.js @@ -48,14 +48,22 @@ function getCommitsSinceLastTag() { if (!latestTag) { // No tags yet, get all commits - return execSync('git log --oneline --format=%s', { encoding: 'utf8' }).trim().split('\n'); + const commits = execSync('git log --oneline --format=%s', { encoding: 'utf8' }).trim(); + return commits ? commits.split('\n') : []; } const commits = execSync(`git log ${latestTag}..HEAD --oneline --format=%s`, { encoding: 'utf8' }).trim(); return commits ? commits.split('\n') : []; } catch (error) { // If no commits since tag or other error, get recent commits - return execSync('git log --oneline --format=%s -n 20', { encoding: 'utf8' }).trim().split('\n'); + try { + const commits = execSync('git log --oneline --format=%s -n 20', { encoding: 'utf8' }).trim(); + return commits ? commits.split('\n') : []; + } catch (innerError) { + // If all git log attempts fail, return empty array + console.warn('Warning: Could not retrieve commit history, defaulting to patch version'); + return []; + } } }