better error handling for git operations

This commit is contained in:
msukkari 2025-05-10 08:37:03 -07:00
parent 6cd6d69817
commit 13b7b352bd
2 changed files with 21 additions and 6 deletions

View file

@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Fixed
- Added better error handling to git operations
## [3.1.3] - 2025-05-07 ## [3.1.3] - 2025-05-07
### Fixed ### Fixed

View file

@ -16,8 +16,12 @@ export const cloneRepository = async (cloneURL: string, path: string, onProgress
await git.cwd({ await git.cwd({
path, path,
}).addConfig("remote.origin.fetch", "+refs/heads/*:refs/heads/*"); }).addConfig("remote.origin.fetch", "+refs/heads/*:refs/heads/*");
} catch (error) { } catch (error: unknown) {
throw new Error(`Failed to clone repository`); if (error instanceof Error) {
throw new Error(`Failed to clone repository: ${error.message}`);
} else {
throw new Error(`Failed to clone repository: ${error}`);
}
} }
} }
@ -37,8 +41,12 @@ export const fetchRepository = async (path: string, onProgress?: (event: SimpleG
"--progress" "--progress"
] ]
); );
} catch (error) { } catch (error: unknown) {
throw new Error(`Failed to fetch repository ${path}`); if (error instanceof Error) {
throw new Error(`Failed to fetch repository ${path}: ${error.message}`);
} else {
throw new Error(`Failed to fetch repository ${path}: ${error}`);
}
} }
} }
@ -57,8 +65,12 @@ export const upsertGitConfig = async (path: string, gitConfig: Record<string, st
for (const [key, value] of Object.entries(gitConfig)) { for (const [key, value] of Object.entries(gitConfig)) {
await git.addConfig(key, value); await git.addConfig(key, value);
} }
} catch (error) { } catch (error: unknown) {
throw new Error(`Failed to set git config ${path}`); if (error instanceof Error) {
throw new Error(`Failed to set git config ${path}: ${error.message}`);
} else {
throw new Error(`Failed to set git config ${path}: ${error}`);
}
} }
} }