diff --git a/src/modules/git/branch.ts b/src/modules/git/branch.ts index 9032444..0380fad 100644 --- a/src/modules/git/branch.ts +++ b/src/modules/git/branch.ts @@ -12,23 +12,34 @@ const getGitBranch = async (verbose?: boolean): Promise => { if (verbose) signale.scope("git branch").debug(`Executing \`${command}\``); // Execute Command - const { stdout, stderr } = await execAsync(command); - - // Catch Errors - if (stderr) { + try { + const { stdout, stderr } = await execAsync(command); + + // Catch Errors + if (stderr) { + signale + .scope("git branch") + .warn( + `Error fetching git branch, command \`${command}\` failed` + ); + if (verbose) signale.error(stderr); + + return null; + } + + if (verbose) + signale + .scope("git branch") + .debug(`Found git branch \`${stdout.replace("\n", "")}\``); + return stdout.replace("\n", "") || null; + } catch (error) { signale .scope("git branch") .warn(`Error fetching git branch, command \`${command}\` failed`); - if (verbose) signale.error(stderr); + if (verbose) signale.error(error); return null; } - - if (verbose) - signale - .scope("git branch") - .debug(`Found git branch \`${stdout.replace("\n", "")}\``); - return stdout.replace("\n", "") || null; }; export default getGitBranch; diff --git a/src/modules/git/commit.ts b/src/modules/git/commit.ts index 8f54d53..736e4fd 100644 --- a/src/modules/git/commit.ts +++ b/src/modules/git/commit.ts @@ -12,25 +12,37 @@ const getGitCommitHash = async (verbose?: boolean): Promise => { if (verbose) signale.scope("git commit").debug(`Executing \`${command}\``); // Execute Command - const { stdout, stderr } = await execAsync(command); - - // Catch Errors - if (stderr) { + try { + // Execute Command + const { stdout, stderr } = await execAsync(command); + + // Catch Errors + if (stderr) { + signale + .scope("git commit") + .warn( + `Error fetching latest commit, command \`${command}\` failed` + ); + if (verbose) signale.error(stderr); + + return null; + } + + if (verbose) + signale + .scope("git commit") + .debug(`Found latest commit \`${stdout.replace("\n", "")}\``); + return stdout.replace("\n", "") || null; + } catch (error) { signale .scope("git commit") .warn( `Error fetching latest commit, command \`${command}\` failed` ); - if (verbose) signale.error(stderr); + if (verbose) signale.error(error); return null; } - - if (verbose) - signale - .scope("git commit") - .debug(`Found latest comit \`${stdout.replace("\n", "")}\``); - return stdout.replace("\n", "") || null; }; export default getGitCommitHash; diff --git a/src/modules/git/user.ts b/src/modules/git/user.ts index 125a1b9..e307b79 100644 --- a/src/modules/git/user.ts +++ b/src/modules/git/user.ts @@ -11,24 +11,33 @@ const getGitUser = async (verbose?: boolean): Promise => { // Debug logging if (verbose) signale.scope("git user").debug(`Executing \`${command}\``); - // Execute Command - const { stdout, stderr } = await execAsync(command); - - // Catch Errors - if (stderr) { + try { + // Execute Command + const { stdout, stderr } = await execAsync(command); + + // Catch Errors + if (stderr) { + signale + .scope("git user") + .warn(`Error fetching git user, command \`${command}\` failed`); + if (verbose) signale.error(stderr); + + return null; + } + + if (verbose) + signale + .scope("git user") + .debug(`Found git user \`${stdout.replace("\n", "")}\``); + return stdout.replace("\n", "") || null; + } catch (error) { signale .scope("git user") .warn(`Error fetching git user, command \`${command}\` failed`); - if (verbose) signale.error(stderr); + if (verbose) signale.error(error); return null; } - - if (verbose) - signale - .scope("git user") - .debug(`Found git user \`${stdout.replace("\n", "")}\``); - return stdout.replace("\n", "") || null; }; export default getGitUser;