Skip to content

Commit 13b7b35

Browse files
committed
better error handling for git operations
1 parent 6cd6d69 commit 13b7b35

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- Added better error handling to git operations
12+
1013
## [3.1.3] - 2025-05-07
1114

1215
### Fixed

packages/backend/src/git.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ export const cloneRepository = async (cloneURL: string, path: string, onProgress
1616
await git.cwd({
1717
path,
1818
}).addConfig("remote.origin.fetch", "+refs/heads/*:refs/heads/*");
19-
} catch (error) {
20-
throw new Error(`Failed to clone repository`);
19+
} catch (error: unknown) {
20+
if (error instanceof Error) {
21+
throw new Error(`Failed to clone repository: ${error.message}`);
22+
} else {
23+
throw new Error(`Failed to clone repository: ${error}`);
24+
}
2125
}
2226
}
2327

@@ -37,8 +41,12 @@ export const fetchRepository = async (path: string, onProgress?: (event: SimpleG
3741
"--progress"
3842
]
3943
);
40-
} catch (error) {
41-
throw new Error(`Failed to fetch repository ${path}`);
44+
} catch (error: unknown) {
45+
if (error instanceof Error) {
46+
throw new Error(`Failed to fetch repository ${path}: ${error.message}`);
47+
} else {
48+
throw new Error(`Failed to fetch repository ${path}: ${error}`);
49+
}
4250
}
4351
}
4452

@@ -57,8 +65,12 @@ export const upsertGitConfig = async (path: string, gitConfig: Record<string, st
5765
for (const [key, value] of Object.entries(gitConfig)) {
5866
await git.addConfig(key, value);
5967
}
60-
} catch (error) {
61-
throw new Error(`Failed to set git config ${path}`);
68+
} catch (error: unknown) {
69+
if (error instanceof Error) {
70+
throw new Error(`Failed to set git config ${path}: ${error.message}`);
71+
} else {
72+
throw new Error(`Failed to set git config ${path}: ${error}`);
73+
}
6274
}
6375
}
6476

0 commit comments

Comments
 (0)