Skip to content

Commit 8be0096

Browse files
Add null check before iteration (#19330)
* Add null check before iteration * Bumping task version
1 parent ee56363 commit 8be0096

File tree

10 files changed

+64
-52
lines changed

10 files changed

+64
-52
lines changed

Tasks/NodeToolV0/nodetool.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async function getNode(versionSpec: string, checkLatest: boolean, nodejsMirror:
8787
version = await queryLatestMatch(versionSpec, 'x64', nodejsMirror);
8888
installedArch = 'x64';
8989
}
90-
90+
9191
if (!version) {
9292
throw new Error(taskLib.loc('NodeVersionNotFound', versionSpec, osPlat, installedArch));
9393
}
@@ -131,7 +131,12 @@ async function queryLatestMatch(versionSpec: string, installedArch: string, node
131131
let dataUrl = nodejsMirror + "/index.json";
132132
let rest: restm.RestClient = new restm.RestClient('vsts-node-tool');
133133
let nodeVersions: INodeVersion[] = (await rest.get<INodeVersion[]>(dataUrl)).result;
134-
nodeVersions.forEach((nodeVersion:INodeVersion) => {
134+
if (!nodeVersions) {
135+
// this will be handled by the caller and an error will be thrown
136+
return null;
137+
}
138+
139+
nodeVersions.forEach((nodeVersion: INodeVersion) => {
135140
// ensure this version supports your os and platform
136141
if (nodeVersion.files.indexOf(dataFileName) >= 0) {
137142
// versions in the file are prefixed with 'v', which is not valid SemVer
@@ -149,7 +154,7 @@ async function queryLatestMatch(versionSpec: string, installedArch: string, node
149154
return nodeVersions.find(v => v.semanticVersion === latestVersion).version;
150155
}
151156

152-
async function acquireNode(version: string, installedArch: string, nodejsMirror: string, retryCountOnDownloadFails: number, delayBetweenRetries: number): Promise<string> {
157+
async function acquireNode(version: string, installedArch: string, nodejsMirror: string, retryCountOnDownloadFails: number, delayBetweenRetries: number): Promise<string> {
153158
//
154159
// Download - a tool installer intimately knows how to get the tool (and construct urls)
155160
//
@@ -230,14 +235,13 @@ async function acquireNodeFromFallbackLocation(version: string, nodejsMirror: st
230235
try {
231236
exeUrl = `${nodejsMirror}/v${version}/win-${osArch}/node.exe`;
232237
libUrl = `${nodejsMirror}/v${version}/win-${osArch}/node.lib`;
233-
238+
234239
await toolLib.downloadToolWithRetries(exeUrl, path.join(tempDir, "node.exe"), null, null, retryCountOnDownloadFails, delayBetweenRetries);
235240
await toolLib.downloadToolWithRetries(libUrl, path.join(tempDir, "node.lib"), null, null, retryCountOnDownloadFails, delayBetweenRetries);
236241
}
237242
catch (err) {
238-
if (err['httpStatusCode'] &&
239-
err['httpStatusCode'] == 404)
240-
{
243+
if (err['httpStatusCode'] &&
244+
err['httpStatusCode'] == 404) {
241245
exeUrl = `${nodejsMirror}/v${version}/node.exe`;
242246
libUrl = `${nodejsMirror}/v${version}/node.lib`;
243247

@@ -254,9 +258,9 @@ async function acquireNodeFromFallbackLocation(version: string, nodejsMirror: st
254258
// Check is the system are darwin arm and rosetta is installed
255259
function isDarwinArm(osPlat: string, installedArch: string): boolean {
256260
if (osPlat === 'darwin' && installedArch === 'arm64') {
257-
// Check that Rosetta is installed and returns some pid
258-
const execResult = taskLib.execSync('pgrep', 'oahd');
259-
return execResult.code === 0 && !!execResult.stdout;
261+
// Check that Rosetta is installed and returns some pid
262+
const execResult = taskLib.execSync('pgrep', 'oahd');
263+
return execResult.code === 0 && !!execResult.stdout;
260264
}
261265
return false;
262266
}

Tasks/NodeToolV0/task.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"author": "Microsoft Corporation",
1414
"version": {
1515
"Major": 0,
16-
"Minor": 231,
17-
"Patch": 6
16+
"Minor": 233,
17+
"Patch": 0
1818
},
1919
"satisfies": [
2020
"Node",

Tasks/NodeToolV0/task.loc.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"author": "Microsoft Corporation",
1414
"version": {
1515
"Major": 0,
16-
"Minor": 231,
17-
"Patch": 6
16+
"Minor": 233,
17+
"Patch": 0
1818
},
1919
"satisfies": [
2020
"Node",

_generated/NodeToolV0.versionmap.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Default|0.231.6
2-
Node20-225|0.231.7
1+
Default|0.233.0
2+
Node20-225|0.233.1

_generated/NodeToolV0/nodetool.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async function getNode(versionSpec: string, checkLatest: boolean, nodejsMirror:
8787
version = await queryLatestMatch(versionSpec, 'x64', nodejsMirror);
8888
installedArch = 'x64';
8989
}
90-
90+
9191
if (!version) {
9292
throw new Error(taskLib.loc('NodeVersionNotFound', versionSpec, osPlat, installedArch));
9393
}
@@ -131,7 +131,12 @@ async function queryLatestMatch(versionSpec: string, installedArch: string, node
131131
let dataUrl = nodejsMirror + "/index.json";
132132
let rest: restm.RestClient = new restm.RestClient('vsts-node-tool');
133133
let nodeVersions: INodeVersion[] = (await rest.get<INodeVersion[]>(dataUrl)).result;
134-
nodeVersions.forEach((nodeVersion:INodeVersion) => {
134+
if (!nodeVersions) {
135+
// this will be handled by the caller and an error will be thrown
136+
return null;
137+
}
138+
139+
nodeVersions.forEach((nodeVersion: INodeVersion) => {
135140
// ensure this version supports your os and platform
136141
if (nodeVersion.files.indexOf(dataFileName) >= 0) {
137142
// versions in the file are prefixed with 'v', which is not valid SemVer
@@ -149,7 +154,7 @@ async function queryLatestMatch(versionSpec: string, installedArch: string, node
149154
return nodeVersions.find(v => v.semanticVersion === latestVersion).version;
150155
}
151156

152-
async function acquireNode(version: string, installedArch: string, nodejsMirror: string, retryCountOnDownloadFails: number, delayBetweenRetries: number): Promise<string> {
157+
async function acquireNode(version: string, installedArch: string, nodejsMirror: string, retryCountOnDownloadFails: number, delayBetweenRetries: number): Promise<string> {
153158
//
154159
// Download - a tool installer intimately knows how to get the tool (and construct urls)
155160
//
@@ -230,14 +235,13 @@ async function acquireNodeFromFallbackLocation(version: string, nodejsMirror: st
230235
try {
231236
exeUrl = `${nodejsMirror}/v${version}/win-${osArch}/node.exe`;
232237
libUrl = `${nodejsMirror}/v${version}/win-${osArch}/node.lib`;
233-
238+
234239
await toolLib.downloadToolWithRetries(exeUrl, path.join(tempDir, "node.exe"), null, null, retryCountOnDownloadFails, delayBetweenRetries);
235240
await toolLib.downloadToolWithRetries(libUrl, path.join(tempDir, "node.lib"), null, null, retryCountOnDownloadFails, delayBetweenRetries);
236241
}
237242
catch (err) {
238-
if (err['httpStatusCode'] &&
239-
err['httpStatusCode'] == 404)
240-
{
243+
if (err['httpStatusCode'] &&
244+
err['httpStatusCode'] == 404) {
241245
exeUrl = `${nodejsMirror}/v${version}/node.exe`;
242246
libUrl = `${nodejsMirror}/v${version}/node.lib`;
243247

@@ -254,9 +258,9 @@ async function acquireNodeFromFallbackLocation(version: string, nodejsMirror: st
254258
// Check is the system are darwin arm and rosetta is installed
255259
function isDarwinArm(osPlat: string, installedArch: string): boolean {
256260
if (osPlat === 'darwin' && installedArch === 'arm64') {
257-
// Check that Rosetta is installed and returns some pid
258-
const execResult = taskLib.execSync('pgrep', 'oahd');
259-
return execResult.code === 0 && !!execResult.stdout;
261+
// Check that Rosetta is installed and returns some pid
262+
const execResult = taskLib.execSync('pgrep', 'oahd');
263+
return execResult.code === 0 && !!execResult.stdout;
260264
}
261265
return false;
262266
}

_generated/NodeToolV0/task.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"author": "Microsoft Corporation",
1414
"version": {
1515
"Major": 0,
16-
"Minor": 231,
17-
"Patch": 6
16+
"Minor": 233,
17+
"Patch": 0
1818
},
1919
"satisfies": [
2020
"Node",
@@ -130,7 +130,7 @@
130130
"AgentTempDirNotSet": "Expected Agent.TempDirectory to be set."
131131
},
132132
"_buildConfigMapping": {
133-
"Default": "0.231.6",
134-
"Node20-225": "0.231.7"
133+
"Default": "0.233.0",
134+
"Node20-225": "0.233.1"
135135
}
136136
}

_generated/NodeToolV0/task.loc.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"author": "Microsoft Corporation",
1414
"version": {
1515
"Major": 0,
16-
"Minor": 231,
17-
"Patch": 6
16+
"Minor": 233,
17+
"Patch": 0
1818
},
1919
"satisfies": [
2020
"Node",
@@ -130,7 +130,7 @@
130130
"AgentTempDirNotSet": "ms-resource:loc.messages.AgentTempDirNotSet"
131131
},
132132
"_buildConfigMapping": {
133-
"Default": "0.231.6",
134-
"Node20-225": "0.231.7"
133+
"Default": "0.233.0",
134+
"Node20-225": "0.233.1"
135135
}
136136
}

_generated/NodeToolV0_Node20/nodetool.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async function getNode(versionSpec: string, checkLatest: boolean, nodejsMirror:
8787
version = await queryLatestMatch(versionSpec, 'x64', nodejsMirror);
8888
installedArch = 'x64';
8989
}
90-
90+
9191
if (!version) {
9292
throw new Error(taskLib.loc('NodeVersionNotFound', versionSpec, osPlat, installedArch));
9393
}
@@ -131,7 +131,12 @@ async function queryLatestMatch(versionSpec: string, installedArch: string, node
131131
let dataUrl = nodejsMirror + "/index.json";
132132
let rest: restm.RestClient = new restm.RestClient('vsts-node-tool');
133133
let nodeVersions: INodeVersion[] = (await rest.get<INodeVersion[]>(dataUrl)).result;
134-
nodeVersions.forEach((nodeVersion:INodeVersion) => {
134+
if (!nodeVersions) {
135+
// this will be handled by the caller and an error will be thrown
136+
return null;
137+
}
138+
139+
nodeVersions.forEach((nodeVersion: INodeVersion) => {
135140
// ensure this version supports your os and platform
136141
if (nodeVersion.files.indexOf(dataFileName) >= 0) {
137142
// versions in the file are prefixed with 'v', which is not valid SemVer
@@ -149,7 +154,7 @@ async function queryLatestMatch(versionSpec: string, installedArch: string, node
149154
return nodeVersions.find(v => v.semanticVersion === latestVersion).version;
150155
}
151156

152-
async function acquireNode(version: string, installedArch: string, nodejsMirror: string, retryCountOnDownloadFails: number, delayBetweenRetries: number): Promise<string> {
157+
async function acquireNode(version: string, installedArch: string, nodejsMirror: string, retryCountOnDownloadFails: number, delayBetweenRetries: number): Promise<string> {
153158
//
154159
// Download - a tool installer intimately knows how to get the tool (and construct urls)
155160
//
@@ -230,14 +235,13 @@ async function acquireNodeFromFallbackLocation(version: string, nodejsMirror: st
230235
try {
231236
exeUrl = `${nodejsMirror}/v${version}/win-${osArch}/node.exe`;
232237
libUrl = `${nodejsMirror}/v${version}/win-${osArch}/node.lib`;
233-
238+
234239
await toolLib.downloadToolWithRetries(exeUrl, path.join(tempDir, "node.exe"), null, null, retryCountOnDownloadFails, delayBetweenRetries);
235240
await toolLib.downloadToolWithRetries(libUrl, path.join(tempDir, "node.lib"), null, null, retryCountOnDownloadFails, delayBetweenRetries);
236241
}
237242
catch (err) {
238-
if (err['httpStatusCode'] &&
239-
err['httpStatusCode'] == 404)
240-
{
243+
if (err['httpStatusCode'] &&
244+
err['httpStatusCode'] == 404) {
241245
exeUrl = `${nodejsMirror}/v${version}/node.exe`;
242246
libUrl = `${nodejsMirror}/v${version}/node.lib`;
243247

@@ -254,9 +258,9 @@ async function acquireNodeFromFallbackLocation(version: string, nodejsMirror: st
254258
// Check is the system are darwin arm and rosetta is installed
255259
function isDarwinArm(osPlat: string, installedArch: string): boolean {
256260
if (osPlat === 'darwin' && installedArch === 'arm64') {
257-
// Check that Rosetta is installed and returns some pid
258-
const execResult = taskLib.execSync('pgrep', 'oahd');
259-
return execResult.code === 0 && !!execResult.stdout;
261+
// Check that Rosetta is installed and returns some pid
262+
const execResult = taskLib.execSync('pgrep', 'oahd');
263+
return execResult.code === 0 && !!execResult.stdout;
260264
}
261265
return false;
262266
}

_generated/NodeToolV0_Node20/task.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"author": "Microsoft Corporation",
1414
"version": {
1515
"Major": 0,
16-
"Minor": 231,
17-
"Patch": 7
16+
"Minor": 233,
17+
"Patch": 1
1818
},
1919
"satisfies": [
2020
"Node",
@@ -134,7 +134,7 @@
134134
"AgentTempDirNotSet": "Expected Agent.TempDirectory to be set."
135135
},
136136
"_buildConfigMapping": {
137-
"Default": "0.231.6",
138-
"Node20-225": "0.231.7"
137+
"Default": "0.233.0",
138+
"Node20-225": "0.233.1"
139139
}
140140
}

_generated/NodeToolV0_Node20/task.loc.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"author": "Microsoft Corporation",
1414
"version": {
1515
"Major": 0,
16-
"Minor": 231,
17-
"Patch": 7
16+
"Minor": 233,
17+
"Patch": 1
1818
},
1919
"satisfies": [
2020
"Node",
@@ -134,7 +134,7 @@
134134
"AgentTempDirNotSet": "ms-resource:loc.messages.AgentTempDirNotSet"
135135
},
136136
"_buildConfigMapping": {
137-
"Default": "0.231.6",
138-
"Node20-225": "0.231.7"
137+
"Default": "0.233.0",
138+
"Node20-225": "0.233.1"
139139
}
140140
}

0 commit comments

Comments
 (0)