Skip to content

Commit 5547b9e

Browse files
committed
fix(cache): Not throw err if no cache folders
1 parent be45b27 commit 5547b9e

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

__tests__/setup-go.test.ts

+8-14
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ describe('setup-go', () => {
9898
logSpy = jest.spyOn(core, 'info');
9999
dbgSpy = jest.spyOn(core, 'debug');
100100
getSpy.mockImplementation(() => <im.IGoVersion[] | null>goJsonData);
101-
cnSpy.mockImplementation(line => {
101+
cnSpy.mockImplementation((line) => {
102102
// uncomment to debug
103103
// process.stderr.write('write:' + line + '\n');
104104
});
105-
logSpy.mockImplementation(line => {
105+
logSpy.mockImplementation((line) => {
106106
// uncomment to debug
107107
//process.stderr.write('log:' + line + '\n');
108108
});
109-
dbgSpy.mockImplementation(msg => {
109+
dbgSpy.mockImplementation((line) => {
110110
// uncomment to see debug output
111111
// process.stderr.write(msg + '\n');
112112
});
@@ -295,7 +295,6 @@ describe('setup-go', () => {
295295
findSpy.mockImplementation(() => toolPath);
296296
await main.run();
297297

298-
let expPath = path.join(toolPath, 'bin');
299298
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
300299
});
301300

@@ -462,9 +461,6 @@ describe('setup-go', () => {
462461
inputs['go-version'] = versionSpec;
463462
inputs['token'] = 'faketoken';
464463

465-
let expectedUrl =
466-
'https://github.com/actions/go-versions/releases/download/1.12.14-20200616.18/go-1.12.14-linux-x64.tar.gz';
467-
468464
// ... but not in the local cache
469465
findSpy.mockImplementation(() => '');
470466

@@ -526,7 +522,7 @@ describe('setup-go', () => {
526522
});
527523

528524
mkdirpSpy.mockImplementation(async () => {});
529-
existsSpy.mockImplementation(path => {
525+
existsSpy.mockImplementation(() => {
530526
return false;
531527
});
532528

@@ -707,8 +703,6 @@ describe('setup-go', () => {
707703
const toolPath = path.normalize('/cache/go/1.17.5/x64');
708704
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
709705
cacheSpy.mockImplementation(async () => toolPath);
710-
const expectedUrl =
711-
'https://github.com/actions/go-versions/releases/download/1.17.6-1668090892/go-1.17.6-darwin-x64.tar.gz';
712706

713707
await main.run();
714708

@@ -834,7 +828,7 @@ exclude example.com/thismodule v1.3.0
834828

835829
it('reads version from go.mod', async () => {
836830
inputs['go-version-file'] = 'go.mod';
837-
existsSpy.mockImplementation(path => true);
831+
existsSpy.mockImplementation(() => true);
838832
readFileSpy.mockImplementation(() => Buffer.from(goModContents));
839833

840834
await main.run();
@@ -846,7 +840,7 @@ exclude example.com/thismodule v1.3.0
846840

847841
it('reads version from .go-version', async () => {
848842
inputs['go-version-file'] = '.go-version';
849-
existsSpy.mockImplementation(path => true);
843+
existsSpy.mockImplementation(() => true);
850844
readFileSpy.mockImplementation(() => Buffer.from(`1.13.0${osm.EOL}`));
851845

852846
await main.run();
@@ -859,7 +853,7 @@ exclude example.com/thismodule v1.3.0
859853
it('is overwritten by go-version', async () => {
860854
inputs['go-version'] = '1.13.1';
861855
inputs['go-version-file'] = 'go.mod';
862-
existsSpy.mockImplementation(path => true);
856+
existsSpy.mockImplementation(() => true);
863857
readFileSpy.mockImplementation(() => Buffer.from(goModContents));
864858

865859
await main.run();
@@ -871,7 +865,7 @@ exclude example.com/thismodule v1.3.0
871865

872866
it('reports a read failure', async () => {
873867
inputs['go-version-file'] = 'go.mod';
874-
existsSpy.mockImplementation(path => false);
868+
existsSpy.mockImplementation(() => false);
875869

876870
await main.run();
877871

src/cache-save.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ export async function run() {
1616
try {
1717
await cachePackages();
1818
} catch (error) {
19-
core.setFailed(error.message);
19+
let message = 'Unknown error!';
20+
if (error instanceof Error) {
21+
message = error.message;
22+
}
23+
if (typeof error === 'string') {
24+
message = error;
25+
}
26+
core.setFailed(message);
2027
}
2128
}
2229

@@ -41,9 +48,7 @@ const cachePackages = async () => {
4148

4249
if (nonExistingPaths.length === cachePaths.length) {
4350
core.warning(`There are no cache folders on the disk`);
44-
logWarning(`There are no cache folders on the disk`)
4551
return;
46-
throw new Error(`There are no cache folders on the disk`);
4752
}
4853

4954
if (nonExistingPaths.length) {
@@ -68,7 +73,7 @@ const cachePackages = async () => {
6873
core.info(`Cache saved with the key: ${primaryKey}`);
6974
};
7075

71-
export function logWarning(message: string): void {
76+
function logWarning(message: string): void {
7277
const warningPrefix = '[warning]';
7378
core.info(`${warningPrefix}${message}`);
7479
}

0 commit comments

Comments
 (0)