Skip to content

Commit

Permalink
feat: output details files if install fails
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensby committed Sep 12, 2023
1 parent 80c47f3 commit f27f339
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/main/index.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function findOrDownloadTool(config: VersionConfig): Promise<string> {
}

export default async function install() {
let threw = false;
const {
version,
password,
Expand Down Expand Up @@ -131,10 +132,13 @@ export default async function install() {
core.endGroup();
}
core.info(`SQL Server ${version} installed`);
} catch (e) {
threw = true;
throw e;
} finally {
// For information purposes, output the summary.txt file
// if there was an error, then also fetch the detail.txt file and output that too
const files = await gatherSummaryFiles(core.isDebug());
const files = await gatherSummaryFiles(threw || core.isDebug());
// read the files in parallel
const contents: [string, Buffer][] = await Promise.all(files.map((path) => readFile(path).then((content): [string, Buffer] => {
return [path, content];
Expand Down
12 changes: 11 additions & 1 deletion test/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ describe('install', () => {
expect(coreStub.info).calledWith('test data');
expect(coreStub.endGroup).has.callCount(1);
});
it('fetches summary files even on errors', async () => {
it('fetches summary files with details on errors', async () => {
const stubReadfile = stub(fs, 'readFile');
stubReadfile.resolves(Buffer.from('test data'));
utilsStub.gatherSummaryFiles.resolves(['C:/tmp/summary.txt']);
Expand All @@ -287,13 +287,23 @@ describe('install', () => {
await install();
} catch (e) {
expect(e).to.have.property('message', 'synthetic error');
expect(utilsStub.gatherSummaryFiles).to.have.been.calledOnceWith(true);
expect(coreStub.startGroup).calledOnceWith('summary.txt');
expect(coreStub.info).calledOnceWith('test data');
expect(coreStub.endGroup).has.callCount(1);
return;
}
expect.fail('expected to throw');
});
it('fetches summary detail files during debug', async () => {
const stubReadfile = stub(fs, 'readFile');
stubReadfile.resolves(Buffer.from('test data'));
utilsStub.gatherSummaryFiles.resolves(['C:/tmp/summary.txt']);
coreStub.isDebug.returns(true);
await install();
expect(utilsStub.gatherSummaryFiles).to.have.been.calledOnceWith(true);
expect(coreStub.info).calledWith('test data');
});
it('installs native client if needed', async () => {
utilsStub.gatherInputs.returns({
version: 'box',
Expand Down

0 comments on commit f27f339

Please sign in to comment.