diff --git a/src/handlers/systemInstall.ts b/src/handlers/systemInstall.ts index 7ccd64a..e94b1a4 100644 --- a/src/handlers/systemInstall.ts +++ b/src/handlers/systemInstall.ts @@ -44,13 +44,21 @@ export async function getSystemRepoInfo( ): Promise<(GitCloneOptions & { name: string }) | void> { // If a repository and checkout were specified, use that to return system information. if (repository && checkout) { - const repoName = getGitRepoNameFromUrl(repository); - if (repoName) { - return { - name: repoName, - repository, - checkout, - }; + try { + const repoName = getGitRepoNameFromUrl(repository); + if (repoName) { + return { + name: repoName, + repository, + checkout, + }; + } + } catch (error: unknown) { + if (error instanceof Error) { + return log('error', error.message, EXIT_ERROR); + } else { + throw error; + } } } diff --git a/src/util/getGitRepoNameFromUrl.test.ts b/src/util/getGitRepoNameFromUrl.test.ts index c33bc7c..82d3581 100644 --- a/src/util/getGitRepoNameFromUrl.test.ts +++ b/src/util/getGitRepoNameFromUrl.test.ts @@ -17,11 +17,13 @@ describe('getGitRepoNameFromUrl', () => { ).toBe('emulsify-drupal'); }); - it('can return void if given an invalid git url', () => { + it('can throw an Error if given an invalid git url', () => { expect.assertions(2); - expect(getGitRepoNameFromUrl('')).toBe(undefined); - expect( - getGitRepoNameFromUrl('https://github.com/emulsify-ds/emulsify-drupal') - ).toBe(undefined); + expect(() => { + getGitRepoNameFromUrl(''); + }).toThrow(Error); + expect(() => { + getGitRepoNameFromUrl('https://github.com/emulsify-ds/emulsify-drupal'); + }).toThrow(Error); }); }); diff --git a/src/util/getGitRepoNameFromUrl.ts b/src/util/getGitRepoNameFromUrl.ts index ff3dc06..222723c 100644 --- a/src/util/getGitRepoNameFromUrl.ts +++ b/src/util/getGitRepoNameFromUrl.ts @@ -14,7 +14,7 @@ export default function getGitRepoNameFromUrl(url: string): string | void { // If no .git extension is provided, then this is an invalid git url. if (!gitName.includes('.git')) { - return undefined; + throw new Error('The repository URL must end in .git.'); } return R.head(gitName.split('.')); }