Skip to content

Commit a77cda8

Browse files
authored
Merge pull request #868 from brendandburns/tsc
Upgrade typescript to 4.7.4 and package-lock version to 2
2 parents cf584cc + 6cb6c4f commit a77cda8

File tree

8 files changed

+5120
-37
lines changed

8 files changed

+5120
-37
lines changed

package-lock.json

Lines changed: 5021 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"ts-node": "^8.2.0",
9797
"tslint": "^5.17.0",
9898
"typedoc": "^0.22.15",
99-
"typescript": "~4.1.3"
99+
"typescript": "~4.7.4"
100100
},
101101
"optionalDependencies": {
102102
"openid-client": "^5.1.6"

src/azure_auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class AzureAuth implements Authenticator {
8282
try {
8383
output = proc.execSync(cmd);
8484
} catch (err) {
85-
throw new Error('Failed to refresh token: ' + err.message);
85+
throw new Error('Failed to refresh token: ' + (err as Error).message);
8686
}
8787

8888
const resultObj = JSON.parse(output);

src/gcp_auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class GoogleCloudPlatformAuth implements Authenticator {
7878
try {
7979
output = proc.execSync(cmd);
8080
} catch (err) {
81-
throw new Error('Failed to refresh token: ' + err.message);
81+
throw new Error('Failed to refresh token: ' + (err as Error).message);
8282
}
8383

8484
const resultObj = JSON.parse(output);

src/metrics_test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ describe('Metrics', () => {
180180
await metricsClient.getPodMetrics();
181181
fail('expected thrown error');
182182
} catch (e) {
183-
expect(e.message).to.equal('connect ECONNREFUSED 127.0.0.1:51011');
183+
if (e instanceof Error) {
184+
expect(e.message).to.equal('connect ECONNREFUSED 127.0.0.1:51011');
185+
} else {
186+
fail(`unknown exception type: ${e}`);
187+
}
184188
}
185189
});
186190
it('should throw when no current cluster', async () => {
@@ -194,7 +198,11 @@ describe('Metrics', () => {
194198
await metricsClient.getPodMetrics();
195199
fail('expected thrown error');
196200
} catch (e) {
197-
expect(e.message).to.equal('No currently active cluster');
201+
if (e instanceof Error) {
202+
expect(e.message).to.equal('No currently active cluster');
203+
} else {
204+
fail(`unknown exception type: ${e}`);
205+
}
198206
}
199207
scope.done();
200208
});

src/object.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,9 @@ export class KubernetesObjectApi extends ApisApi {
609609
this.apiVersionResourceCache[apiVersion] = getApiResponse.body;
610610
return this.apiVersionResourceCache[apiVersion].resources.find((r) => r.kind === kind);
611611
} catch (e) {
612-
e.message = `Failed to fetch resource metadata for ${apiVersion}/${kind}: ${e.message}`;
612+
if (e instanceof Error) {
613+
e.message = `Failed to fetch resource metadata for ${apiVersion}/${kind}: ${e.message}`;
614+
}
613615
throw e;
614616
}
615617
}

src/object_test.ts

Lines changed: 70 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { fail } from 'assert';
12
import { expect } from 'chai';
23
import nock = require('nock');
34
import { V1APIResource, V1APIResourceList, V1Secret } from './api';
@@ -897,7 +898,11 @@ describe('KubernetesObject', () => {
897898
expect.fail('should have thrown error');
898899
} catch (e) {
899900
thrown = true;
900-
expect(e.message).to.equal('Required spec property kind is not set');
901+
if (e instanceof Error) {
902+
expect(e.message).to.equal('Required spec property kind is not set');
903+
} else {
904+
fail(`unknown exception: ${e}`);
905+
}
901906
}
902907
expect(thrown).to.be.true;
903908
});
@@ -920,7 +925,11 @@ describe('KubernetesObject', () => {
920925
expect.fail('should have thrown error');
921926
} catch (e) {
922927
thrown = true;
923-
expect(e.message).to.equal('Required spec property name is not set');
928+
if (e instanceof Error) {
929+
expect(e.message).to.equal('Required spec property name is not set');
930+
} else {
931+
fail(`unknown exception: ${e}`);
932+
}
924933
}
925934
expect(thrown).to.be.true;
926935
scope.done();
@@ -945,7 +954,11 @@ describe('KubernetesObject', () => {
945954
expect.fail('should have thrown error');
946955
} catch (e) {
947956
thrown = true;
948-
expect(e.message).to.equal('Unrecognized API version and kind: v1 Ingress');
957+
if (e instanceof Error) {
958+
expect(e.message).to.equal('Unrecognized API version and kind: v1 Ingress');
959+
} else {
960+
fail(`unknown exception: ${e}`);
961+
}
949962
}
950963
expect(thrown).to.be.true;
951964
scope.done();
@@ -1005,9 +1018,13 @@ describe('KubernetesObject', () => {
10051018
await client.resource((a as unknown) as string, 'Service');
10061019
} catch (e) {
10071020
thrown = true;
1008-
expect(e.message).to.equal(
1009-
'Required parameter apiVersion was null or undefined when calling resource',
1010-
);
1021+
if (e instanceof Error) {
1022+
expect(e.message).to.equal(
1023+
'Required parameter apiVersion was null or undefined when calling resource',
1024+
);
1025+
} else {
1026+
fail(`unknown exception: ${e}`);
1027+
}
10111028
}
10121029
expect(thrown).to.be.true;
10131030
}
@@ -1020,9 +1037,13 @@ describe('KubernetesObject', () => {
10201037
await client.resource('v1', (a as unknown) as string);
10211038
} catch (e) {
10221039
thrown = true;
1023-
expect(e.message).to.equal(
1024-
'Required parameter kind was null or undefined when calling resource',
1025-
);
1040+
if (e instanceof Error) {
1041+
expect(e.message).to.equal(
1042+
'Required parameter kind was null or undefined when calling resource',
1043+
);
1044+
} else {
1045+
fail(`unknown exception: ${e}`);
1046+
}
10261047
}
10271048
expect(thrown).to.be.true;
10281049
}
@@ -1920,9 +1941,13 @@ describe('KubernetesObject', () => {
19201941
expect.fail('should have thrown an error');
19211942
} catch (e) {
19221943
thrown = true;
1923-
expect(e.message).to.contain(
1924-
'Required parameter spec was null or undefined when calling ',
1925-
);
1944+
if (e instanceof Error) {
1945+
expect(e.message).to.contain(
1946+
'Required parameter spec was null or undefined when calling ',
1947+
);
1948+
} else {
1949+
fail(`unknown exception: ${e}`);
1950+
}
19261951
}
19271952
expect(thrown).to.be.true;
19281953
}
@@ -1957,7 +1982,11 @@ describe('KubernetesObject', () => {
19571982
expect.fail('should have thrown error');
19581983
} catch (e) {
19591984
thrown = true;
1960-
expect(e.message).to.contain('Nock: No match for request');
1985+
if (e instanceof Error) {
1986+
expect(e.message).to.contain('Nock: No match for request');
1987+
} else {
1988+
fail(`unknown exception: ${e}`);
1989+
}
19611990
}
19621991
expect(thrown).to.be.true;
19631992
});
@@ -2015,8 +2044,12 @@ describe('KubernetesObject', () => {
20152044
await client.create(s);
20162045
} catch (e) {
20172046
thrown = true;
2018-
expect(e.statusCode).to.equal(422);
2019-
expect(e.message).to.equal('HTTP request failed');
2047+
if (e instanceof Error) {
2048+
expect((e as any).statusCode).to.equal(422);
2049+
expect(e.message).to.equal('HTTP request failed');
2050+
} else {
2051+
fail(`unknown exception: ${e}`);
2052+
}
20202053
}
20212054
expect(thrown).to.be.true;
20222055
scope.done();
@@ -2064,10 +2097,14 @@ describe('KubernetesObject', () => {
20642097
await client.create(d);
20652098
} catch (e) {
20662099
thrown = true;
2067-
expect(e.statusCode).to.equal(404);
2068-
expect(e.message).to.equal(
2069-
'Failed to fetch resource metadata for applications/v1/Deployment: HTTP request failed',
2070-
);
2100+
if (e instanceof Error) {
2101+
expect((e as any).statusCode).to.equal(404);
2102+
expect(e.message).to.equal(
2103+
'Failed to fetch resource metadata for applications/v1/Deployment: HTTP request failed',
2104+
);
2105+
} else {
2106+
fail(`unknown exception: ${e}`);
2107+
}
20712108
}
20722109
expect(thrown).to.be.true;
20732110
scope.done();
@@ -2080,9 +2117,13 @@ describe('KubernetesObject', () => {
20802117
expect.fail('should have thrown an error');
20812118
} catch (e) {
20822119
thrown = true;
2083-
expect(e.message).to.contain(
2084-
'Required parameter apiVersion was null or undefined when calling ',
2085-
);
2120+
if (e instanceof Error) {
2121+
expect(e.message).to.contain(
2122+
'Required parameter apiVersion was null or undefined when calling ',
2123+
);
2124+
} else {
2125+
fail(`unknown exception: ${e}`);
2126+
}
20862127
}
20872128
expect(thrown).to.be.true;
20882129
});
@@ -2094,7 +2135,13 @@ describe('KubernetesObject', () => {
20942135
expect.fail('should have thrown an error');
20952136
} catch (e) {
20962137
thrown = true;
2097-
expect(e.message).to.contain('Required parameter kind was null or undefined when calling ');
2138+
if (e instanceof Error) {
2139+
expect(e.message).to.contain(
2140+
'Required parameter kind was null or undefined when calling ',
2141+
);
2142+
} else {
2143+
fail(`unknown exception: ${e}`);
2144+
}
20982145
}
20992146
expect(thrown).to.be.true;
21002147
});

src/portforward_test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { fail } from 'assert';
12
import { expect } from 'chai';
23
import { ReadableStreamBuffer, WritableStreamBuffer } from 'stream-buffers';
34
import { anyFunction, capture, instance, mock, reset, verify } from 'ts-mockito';
@@ -127,13 +128,23 @@ describe('PortForward', () => {
127128
await portForward.portForward('ns', 'pod', [], osStream, osStream, isStream);
128129
expect(false, 'should have thrown').to.equal(true);
129130
} catch (err) {
130-
expect(err.toString()).to.equal('Error: You must provide at least one port to forward to.');
131+
if (err instanceof Error) {
132+
expect(err.toString()).to.equal('Error: You must provide at least one port to forward to.');
133+
} else {
134+
fail(`unknown exception: ${err}`);
135+
}
131136
}
132137
try {
133138
await portForward.portForward('ns', 'pod', [1, 2], osStream, osStream, isStream);
134139
expect(false, 'should have thrown').to.equal(true);
135140
} catch (err) {
136-
expect(err.toString()).to.equal('Error: Only one port is currently supported for port-forward');
141+
if (err instanceof Error) {
142+
expect(err.toString()).to.equal(
143+
'Error: Only one port is currently supported for port-forward',
144+
);
145+
} else {
146+
fail(`unknown exception: ${err}`);
147+
}
137148
}
138149
});
139150
});

0 commit comments

Comments
 (0)