Skip to content

Commit b9278e9

Browse files
authored
Merge pull request tediousjs#6 from dhensby/pulls/details-on-error
feat: output details files if install fails
2 parents 80c47f3 + f27f339 commit b9278e9

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

lib/main/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/install.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function findOrDownloadTool(config: VersionConfig): Promise<string> {
3333
}
3434

3535
export default async function install() {
36+
let threw = false;
3637
const {
3738
version,
3839
password,
@@ -131,10 +132,13 @@ export default async function install() {
131132
core.endGroup();
132133
}
133134
core.info(`SQL Server ${version} installed`);
135+
} catch (e) {
136+
threw = true;
137+
throw e;
134138
} finally {
135139
// For information purposes, output the summary.txt file
136140
// if there was an error, then also fetch the detail.txt file and output that too
137-
const files = await gatherSummaryFiles(core.isDebug());
141+
const files = await gatherSummaryFiles(threw || core.isDebug());
138142
// read the files in parallel
139143
const contents: [string, Buffer][] = await Promise.all(files.map((path) => readFile(path).then((content): [string, Buffer] => {
140144
return [path, content];

test/install.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ describe('install', () => {
278278
expect(coreStub.info).calledWith('test data');
279279
expect(coreStub.endGroup).has.callCount(1);
280280
});
281-
it('fetches summary files even on errors', async () => {
281+
it('fetches summary files with details on errors', async () => {
282282
const stubReadfile = stub(fs, 'readFile');
283283
stubReadfile.resolves(Buffer.from('test data'));
284284
utilsStub.gatherSummaryFiles.resolves(['C:/tmp/summary.txt']);
@@ -287,13 +287,23 @@ describe('install', () => {
287287
await install();
288288
} catch (e) {
289289
expect(e).to.have.property('message', 'synthetic error');
290+
expect(utilsStub.gatherSummaryFiles).to.have.been.calledOnceWith(true);
290291
expect(coreStub.startGroup).calledOnceWith('summary.txt');
291292
expect(coreStub.info).calledOnceWith('test data');
292293
expect(coreStub.endGroup).has.callCount(1);
293294
return;
294295
}
295296
expect.fail('expected to throw');
296297
});
298+
it('fetches summary detail files during debug', async () => {
299+
const stubReadfile = stub(fs, 'readFile');
300+
stubReadfile.resolves(Buffer.from('test data'));
301+
utilsStub.gatherSummaryFiles.resolves(['C:/tmp/summary.txt']);
302+
coreStub.isDebug.returns(true);
303+
await install();
304+
expect(utilsStub.gatherSummaryFiles).to.have.been.calledOnceWith(true);
305+
expect(coreStub.info).calledWith('test data');
306+
});
297307
it('installs native client if needed', async () => {
298308
utilsStub.gatherInputs.returns({
299309
version: 'box',

0 commit comments

Comments
 (0)