Skip to content

Commit

Permalink
Fix #19726 (#19755)
Browse files Browse the repository at this point in the history
* Fix #19726

Add type check to avoid errors when the thrown exception is an object

* Format the code
  • Loading branch information
LeftTwixWand authored Apr 9, 2024
1 parent e496052 commit 5f964db
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 74 deletions.
13 changes: 8 additions & 5 deletions Tasks/AzureCLIV1/azureclitask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,19 @@ export class azureclitask {

//set the task result to either succeeded or failed based on error was thrown or not
if (toolExecutionError) {
let message = tl.loc("ScriptFailed", toolExecutionError);
let message = tl.loc('ScriptFailed', toolExecutionError);

const expiredSecretErrorCode = "AADSTS7000222";
let serviceEndpointSecretIsExpired = toolExecutionError.indexOf(expiredSecretErrorCode) >= 0;
if (serviceEndpointSecretIsExpired) {
if (typeof toolExecutionError === 'string') {
const expiredSecretErrorCode = 'AADSTS7000222';
let serviceEndpointSecretIsExpired = toolExecutionError.indexOf(expiredSecretErrorCode) >= 0;

if (serviceEndpointSecretIsExpired) {
const organizationURL = tl.getVariable('System.CollectionUri');
const projectName = tl.getVariable('System.TeamProject');
const serviceConnectionLink = encodeURI(`${organizationURL}${projectName}/_settings/adminservices?resourceId=${connectedService}`);

message = tl.loc('ExpiredServicePrincipalMessageWithLink', serviceConnectionLink);
}
}

tl.setResult(tl.TaskResult.Failed, message);
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCLIV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 1,
"Minor": 238,
"Patch": 0
"Patch": 2
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCLIV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 1,
"Minor": 238,
"Patch": 0
"Patch": 2
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down
21 changes: 12 additions & 9 deletions Tasks/AzureCLIV2/azureclitask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,22 @@ export class azureclitask {
if(toolExecutionError === FAIL_ON_STDERR) {
tl.setResult(tl.TaskResult.Failed, tl.loc("ScriptFailedStdErr"));
} else if (toolExecutionError) {
let message = tl.loc("ScriptFailed", toolExecutionError);
let message = tl.loc('ScriptFailed', toolExecutionError);

const expiredSecretErrorCode = "AADSTS7000222";
if (typeof toolExecutionError === 'string') {
const expiredSecretErrorCode = 'AADSTS7000222';
let serviceEndpointSecretIsExpired = toolExecutionError.indexOf(expiredSecretErrorCode) >= 0;

if (serviceEndpointSecretIsExpired) {
const organizationURL = tl.getVariable('System.CollectionUri');
const projectName = tl.getVariable('System.TeamProject');
const serviceConnectionLink = encodeURI(`${organizationURL}${projectName}/_settings/adminservices?resourceId=${connectedService}`);
message = tl.loc('ExpiredServicePrincipalMessageWithLink', serviceConnectionLink);
const organizationURL = tl.getVariable('System.CollectionUri');
const projectName = tl.getVariable('System.TeamProject');
const serviceConnectionLink = encodeURI(`${organizationURL}${projectName}/_settings/adminservices?resourceId=${connectedService}`);

message = tl.loc('ExpiredServicePrincipalMessageWithLink', serviceConnectionLink);
}

tl.setResult(tl.TaskResult.Failed, message);
}

tl.setResult(tl.TaskResult.Failed, message);
} else if (exitCode != 0){
tl.setResult(tl.TaskResult.Failed, tl.loc("ScriptFailedWithExitCode", exitCode));
}
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCLIV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 238,
"Patch": 0
"Patch": 2
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCLIV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 238,
"Patch": 0
"Patch": 2
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down
4 changes: 2 additions & 2 deletions _generated/AzureCLIV1.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|1.238.0
Node20_229_2|1.238.1
Default|1.238.2
Node20_229_2|1.238.3
13 changes: 8 additions & 5 deletions _generated/AzureCLIV1/azureclitask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,19 @@ export class azureclitask {

//set the task result to either succeeded or failed based on error was thrown or not
if (toolExecutionError) {
let message = tl.loc("ScriptFailed", toolExecutionError);
let message = tl.loc('ScriptFailed', toolExecutionError);

const expiredSecretErrorCode = "AADSTS7000222";
let serviceEndpointSecretIsExpired = toolExecutionError.indexOf(expiredSecretErrorCode) >= 0;
if (serviceEndpointSecretIsExpired) {
if (typeof toolExecutionError === 'string') {
const expiredSecretErrorCode = 'AADSTS7000222';
let serviceEndpointSecretIsExpired = toolExecutionError.indexOf(expiredSecretErrorCode) >= 0;

if (serviceEndpointSecretIsExpired) {
const organizationURL = tl.getVariable('System.CollectionUri');
const projectName = tl.getVariable('System.TeamProject');
const serviceConnectionLink = encodeURI(`${organizationURL}${projectName}/_settings/adminservices?resourceId=${connectedService}`);

message = tl.loc('ExpiredServicePrincipalMessageWithLink', serviceConnectionLink);
}
}

tl.setResult(tl.TaskResult.Failed, message);
Expand Down
6 changes: 3 additions & 3 deletions _generated/AzureCLIV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 1,
"Minor": 238,
"Patch": 0
"Patch": 2
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand Down Expand Up @@ -161,7 +161,7 @@
"ExpiredServicePrincipalMessageWithLink": "Secret expired, update service connection at\u00A0%s See\u00A0https://aka.ms/azdo-rm-workload-identity-conversion to learn more about conversion to secret-less service connections."
},
"_buildConfigMapping": {
"Default": "1.238.0",
"Node20_229_2": "1.238.1"
"Default": "1.238.2",
"Node20_229_2": "1.238.3"
}
}
6 changes: 3 additions & 3 deletions _generated/AzureCLIV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 1,
"Minor": 238,
"Patch": 0
"Patch": 2
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down Expand Up @@ -161,7 +161,7 @@
"ExpiredServicePrincipalMessageWithLink": "ms-resource:loc.messages.ExpiredServicePrincipalMessageWithLink"
},
"_buildConfigMapping": {
"Default": "1.238.0",
"Node20_229_2": "1.238.1"
"Default": "1.238.2",
"Node20_229_2": "1.238.3"
}
}
13 changes: 8 additions & 5 deletions _generated/AzureCLIV1_Node20/azureclitask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,19 @@ export class azureclitask {

//set the task result to either succeeded or failed based on error was thrown or not
if (toolExecutionError) {
let message = tl.loc("ScriptFailed", toolExecutionError);
let message = tl.loc('ScriptFailed', toolExecutionError);

const expiredSecretErrorCode = "AADSTS7000222";
let serviceEndpointSecretIsExpired = toolExecutionError.indexOf(expiredSecretErrorCode) >= 0;
if (serviceEndpointSecretIsExpired) {
if (typeof toolExecutionError === 'string') {
const expiredSecretErrorCode = 'AADSTS7000222';
let serviceEndpointSecretIsExpired = toolExecutionError.indexOf(expiredSecretErrorCode) >= 0;

if (serviceEndpointSecretIsExpired) {
const organizationURL = tl.getVariable('System.CollectionUri');
const projectName = tl.getVariable('System.TeamProject');
const serviceConnectionLink = encodeURI(`${organizationURL}${projectName}/_settings/adminservices?resourceId=${connectedService}`);

message = tl.loc('ExpiredServicePrincipalMessageWithLink', serviceConnectionLink);
}
}

tl.setResult(tl.TaskResult.Failed, message);
Expand Down
6 changes: 3 additions & 3 deletions _generated/AzureCLIV1_Node20/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 1,
"Minor": 238,
"Patch": 1
"Patch": 3
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand Down Expand Up @@ -165,7 +165,7 @@
"ExpiredServicePrincipalMessageWithLink": "Secret expired, update service connection at\u00A0%s See\u00A0https://aka.ms/azdo-rm-workload-identity-conversion to learn more about conversion to secret-less service connections."
},
"_buildConfigMapping": {
"Default": "1.238.0",
"Node20_229_2": "1.238.1"
"Default": "1.238.2",
"Node20_229_2": "1.238.3"
}
}
6 changes: 3 additions & 3 deletions _generated/AzureCLIV1_Node20/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 1,
"Minor": 238,
"Patch": 1
"Patch": 3
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down Expand Up @@ -165,7 +165,7 @@
"ExpiredServicePrincipalMessageWithLink": "ms-resource:loc.messages.ExpiredServicePrincipalMessageWithLink"
},
"_buildConfigMapping": {
"Default": "1.238.0",
"Node20_229_2": "1.238.1"
"Default": "1.238.2",
"Node20_229_2": "1.238.3"
}
}
4 changes: 2 additions & 2 deletions _generated/AzureCLIV2.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|2.238.0
Node20_229_2|2.238.1
Default|2.238.2
Node20_229_2|2.238.3
21 changes: 12 additions & 9 deletions _generated/AzureCLIV2/azureclitask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,22 @@ export class azureclitask {
if(toolExecutionError === FAIL_ON_STDERR) {
tl.setResult(tl.TaskResult.Failed, tl.loc("ScriptFailedStdErr"));
} else if (toolExecutionError) {
let message = tl.loc("ScriptFailed", toolExecutionError);
let message = tl.loc('ScriptFailed', toolExecutionError);

const expiredSecretErrorCode = "AADSTS7000222";
if (typeof toolExecutionError === 'string') {
const expiredSecretErrorCode = 'AADSTS7000222';
let serviceEndpointSecretIsExpired = toolExecutionError.indexOf(expiredSecretErrorCode) >= 0;

if (serviceEndpointSecretIsExpired) {
const organizationURL = tl.getVariable('System.CollectionUri');
const projectName = tl.getVariable('System.TeamProject');
const serviceConnectionLink = encodeURI(`${organizationURL}${projectName}/_settings/adminservices?resourceId=${connectedService}`);
message = tl.loc('ExpiredServicePrincipalMessageWithLink', serviceConnectionLink);
const organizationURL = tl.getVariable('System.CollectionUri');
const projectName = tl.getVariable('System.TeamProject');
const serviceConnectionLink = encodeURI(`${organizationURL}${projectName}/_settings/adminservices?resourceId=${connectedService}`);

message = tl.loc('ExpiredServicePrincipalMessageWithLink', serviceConnectionLink);
}

tl.setResult(tl.TaskResult.Failed, message);
}

tl.setResult(tl.TaskResult.Failed, message);
} else if (exitCode != 0){
tl.setResult(tl.TaskResult.Failed, tl.loc("ScriptFailedWithExitCode", exitCode));
}
Expand Down
6 changes: 3 additions & 3 deletions _generated/AzureCLIV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 238,
"Patch": 0
"Patch": 2
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand Down Expand Up @@ -204,7 +204,7 @@
"ExpiredServicePrincipalMessageWithLink": "Secret expired, update service connection at\u00A0%s See\u00A0https://aka.ms/azdo-rm-workload-identity-conversion to learn more about conversion to secret-less service connections."
},
"_buildConfigMapping": {
"Default": "2.238.0",
"Node20_229_2": "2.238.1"
"Default": "2.238.2",
"Node20_229_2": "2.238.3"
}
}
6 changes: 3 additions & 3 deletions _generated/AzureCLIV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 238,
"Patch": 0
"Patch": 2
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down Expand Up @@ -204,7 +204,7 @@
"ExpiredServicePrincipalMessageWithLink": "ms-resource:loc.messages.ExpiredServicePrincipalMessageWithLink"
},
"_buildConfigMapping": {
"Default": "2.238.0",
"Node20_229_2": "2.238.1"
"Default": "2.238.2",
"Node20_229_2": "2.238.3"
}
}
21 changes: 12 additions & 9 deletions _generated/AzureCLIV2_Node20/azureclitask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,22 @@ export class azureclitask {
if(toolExecutionError === FAIL_ON_STDERR) {
tl.setResult(tl.TaskResult.Failed, tl.loc("ScriptFailedStdErr"));
} else if (toolExecutionError) {
let message = tl.loc("ScriptFailed", toolExecutionError);
let message = tl.loc('ScriptFailed', toolExecutionError);

const expiredSecretErrorCode = "AADSTS7000222";
if (typeof toolExecutionError === 'string') {
const expiredSecretErrorCode = 'AADSTS7000222';
let serviceEndpointSecretIsExpired = toolExecutionError.indexOf(expiredSecretErrorCode) >= 0;

if (serviceEndpointSecretIsExpired) {
const organizationURL = tl.getVariable('System.CollectionUri');
const projectName = tl.getVariable('System.TeamProject');
const serviceConnectionLink = encodeURI(`${organizationURL}${projectName}/_settings/adminservices?resourceId=${connectedService}`);
message = tl.loc('ExpiredServicePrincipalMessageWithLink', serviceConnectionLink);
const organizationURL = tl.getVariable('System.CollectionUri');
const projectName = tl.getVariable('System.TeamProject');
const serviceConnectionLink = encodeURI(`${organizationURL}${projectName}/_settings/adminservices?resourceId=${connectedService}`);

message = tl.loc('ExpiredServicePrincipalMessageWithLink', serviceConnectionLink);
}

tl.setResult(tl.TaskResult.Failed, message);
}

tl.setResult(tl.TaskResult.Failed, message);
} else if (exitCode != 0){
tl.setResult(tl.TaskResult.Failed, tl.loc("ScriptFailedWithExitCode", exitCode));
}
Expand Down
6 changes: 3 additions & 3 deletions _generated/AzureCLIV2_Node20/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 238,
"Patch": 1
"Patch": 3
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand Down Expand Up @@ -208,7 +208,7 @@
"ExpiredServicePrincipalMessageWithLink": "Secret expired, update service connection at\u00A0%s See\u00A0https://aka.ms/azdo-rm-workload-identity-conversion to learn more about conversion to secret-less service connections."
},
"_buildConfigMapping": {
"Default": "2.238.0",
"Node20_229_2": "2.238.1"
"Default": "2.238.2",
"Node20_229_2": "2.238.3"
}
}
6 changes: 3 additions & 3 deletions _generated/AzureCLIV2_Node20/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 238,
"Patch": 1
"Patch": 3
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down Expand Up @@ -208,7 +208,7 @@
"ExpiredServicePrincipalMessageWithLink": "ms-resource:loc.messages.ExpiredServicePrincipalMessageWithLink"
},
"_buildConfigMapping": {
"Default": "2.238.0",
"Node20_229_2": "2.238.1"
"Default": "2.238.2",
"Node20_229_2": "2.238.3"
}
}

0 comments on commit 5f964db

Please sign in to comment.