From 9a8045b6f239974810c088ede6df9bb4829a0b01 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 10 Feb 2017 04:10:55 -0500 Subject: [PATCH] Fixes exception trapping --- src/git/git.ts | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/git/git.ts b/src/git/git.ts index a42eff7..fcf1be9 100644 --- a/src/git/git.ts +++ b/src/git/git.ts @@ -129,27 +129,28 @@ export default class Git { return gitCommand(repoPath, ...params); } - static getVersionedFile(fileName: string, repoPath: string, sha: string) { + static async getVersionedFile(fileName: string, repoPath: string, sha: string) { + const data = await Git.getVersionedFileText(fileName, repoPath, sha); + + const ext = path.extname(fileName); return new Promise((resolve, reject) => { - Git.getVersionedFileText(fileName, repoPath, sha).then(data => { - const ext = path.extname(fileName); - tmp.file({ prefix: `${path.basename(fileName, ext)}-${sha}__`, postfix: ext }, - (err, destination, fd, cleanupCallback) => { + tmp.file({ prefix: `${path.basename(fileName, ext)}-${sha}__`, postfix: ext }, + (err, destination, fd, cleanupCallback) => { + if (err) { + reject(err); + return; + } + + Logger.log(`getVersionedFile(${fileName}, ${repoPath}, ${sha}); destination=${destination}`); + fs.appendFile(destination, data, err => { if (err) { reject(err); return; } - Logger.log(`getVersionedFile(${fileName}, ${repoPath}, ${sha}); destination=${destination}`); - fs.appendFile(destination, data, err => { - if (err) { - reject(err); - return; - } - resolve(destination); - }); + resolve(destination); }); - }); + }); }); }