Skip to content

Commit aab0401

Browse files
feature/Add error handling in case of git commit feature
1 parent 3e5ebbd commit aab0401

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "api-explorer",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"private": true,
55
"scripts": {
66
"dev": "vite & ts-node server/app.ts",

server/app.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,20 @@ console.log(
121121
)
122122

123123
// Get commit ID
124-
export const commitId = execSync('git rev-parse HEAD').toString().trim();
125-
console.log('Current Commit ID:', commitId);
124+
export let commitId = '';
125+
126+
try {
127+
// Try to get the commit ID
128+
commitId = execSync('git rev-parse HEAD', { encoding: 'utf-8' }).trim();
129+
console.log('Current Commit ID:', commitId);
130+
} catch (error) {
131+
// Log the error but do not terminate the process
132+
console.error('Warning: Failed to retrieve the commit ID. Proceeding without it.');
133+
console.error('Error details:', error.message);
134+
commitId = 'unknown'; // Assign a fallback value
135+
}
136+
// Continue execution with or without a valid commit ID
137+
console.log('Execution continues with commitId:', commitId);
126138

127139
// Error Handling to Shut Down the App
128140
server.on('error', (err) => {

0 commit comments

Comments
 (0)