From 6ed0a9537eb25768e776296213a802098947905a Mon Sep 17 00:00:00 2001 From: DaniilShmelev Date: Thu, 15 Apr 2021 17:33:37 +0300 Subject: [PATCH 1/4] fail on exceptions --- .../Strings/resources.resjson/en-US/resources.resjson | 1 + Tasks/FtpUploadV1/ftpuploadtask.ts | 11 +++++++++-- Tasks/FtpUploadV1/task.json | 3 ++- Tasks/FtpUploadV1/task.loc.json | 1 + .../Strings/resources.resjson/en-US/resources.resjson | 1 + Tasks/FtpUploadV2/ftpuploadtask.ts | 8 +++++++- Tasks/FtpUploadV2/task.json | 3 ++- Tasks/FtpUploadV2/task.loc.json | 1 + 8 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Tasks/FtpUploadV1/Strings/resources.resjson/en-US/resources.resjson b/Tasks/FtpUploadV1/Strings/resources.resjson/en-US/resources.resjson index 021ad3a90868..a20cf8bd672f 100644 --- a/Tasks/FtpUploadV1/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/FtpUploadV1/Strings/resources.resjson/en-US/resources.resjson @@ -34,6 +34,7 @@ "loc.messages.Disconnected": "disconnected", "loc.messages.DisconnectHost": "disconnecting from: %s", "loc.messages.FTPConnected": "connected: %s", + "loc.messages.InvalidFTPOptions": "There was an error when reading FTP options: %s", "loc.messages.FTPNoHostSpecified": "The FTP server URL must include a host name", "loc.messages.FTPNoProtocolSpecified": "The FTP server URL must begin with ftp:// or ftps://", "loc.messages.UploadRemoteDir": "uploading files to remote directory: %s", diff --git a/Tasks/FtpUploadV1/ftpuploadtask.ts b/Tasks/FtpUploadV1/ftpuploadtask.ts index 041bd9671d1c..a6e0e0d6d8d8 100644 --- a/Tasks/FtpUploadV1/ftpuploadtask.ts +++ b/Tasks/FtpUploadV1/ftpuploadtask.ts @@ -63,7 +63,14 @@ function getFtpOptions(): FtpOptions { function doWork() { tl.setResourcePath(path.join( __dirname, 'task.json')); - let ftpOptions: FtpOptions = getFtpOptions(); + let ftpOptions: FtpOptions; + try { + ftpOptions = getFtpOptions(); + } catch (err) { + tl.setResult(tl.TaskResult.Failed, tl.loc('InvalidFTPOptions', err.toString())); + return; + } + if (!ftpOptions.serverEndpointUrl.protocol) { tl.setResult(tl.TaskResult.Failed, tl.loc('FTPNoProtocolSpecified')); } @@ -161,4 +168,4 @@ function doWork() { ftpClient.connect({ 'host': hostName, 'port': port, 'user': ftpOptions.username, 'password': ftpOptions.password, 'secure': secure, 'secureOptions': secureOptions, 'debug': debugLogger }); } -doWork(); \ No newline at end of file +doWork(); diff --git a/Tasks/FtpUploadV1/task.json b/Tasks/FtpUploadV1/task.json index 0331805eaf73..a37f624aa682 100644 --- a/Tasks/FtpUploadV1/task.json +++ b/Tasks/FtpUploadV1/task.json @@ -182,10 +182,11 @@ "Disconnected": "disconnected", "DisconnectHost": "disconnecting from: %s", "FTPConnected": "connected: %s", + "InvalidFTPOptions": "There was an error when reading FTP options: %s", "FTPNoHostSpecified": "The FTP server URL must include a host name", "FTPNoProtocolSpecified": "The FTP server URL must begin with ftp:// or ftps://", "UploadRemoteDir": "uploading files to remote directory: %s", "UploadSucceedMsg": "FTP upload successful %s", "UploadSucceedRes": "FTP upload successful" } -} \ No newline at end of file +} diff --git a/Tasks/FtpUploadV1/task.loc.json b/Tasks/FtpUploadV1/task.loc.json index f3336256dc47..c3a9650f2384 100644 --- a/Tasks/FtpUploadV1/task.loc.json +++ b/Tasks/FtpUploadV1/task.loc.json @@ -182,6 +182,7 @@ "Disconnected": "ms-resource:loc.messages.Disconnected", "DisconnectHost": "ms-resource:loc.messages.DisconnectHost", "FTPConnected": "ms-resource:loc.messages.FTPConnected", + "InvalidFTPOptions": "ms-resource:loc.messages.InvalidFTPOptions", "FTPNoHostSpecified": "ms-resource:loc.messages.FTPNoHostSpecified", "FTPNoProtocolSpecified": "ms-resource:loc.messages.FTPNoProtocolSpecified", "UploadRemoteDir": "ms-resource:loc.messages.UploadRemoteDir", diff --git a/Tasks/FtpUploadV2/Strings/resources.resjson/en-US/resources.resjson b/Tasks/FtpUploadV2/Strings/resources.resjson/en-US/resources.resjson index f6dc665d8a74..98c922de5795 100644 --- a/Tasks/FtpUploadV2/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/FtpUploadV2/Strings/resources.resjson/en-US/resources.resjson @@ -36,6 +36,7 @@ "loc.messages.Disconnected": "disconnected", "loc.messages.DisconnectHost": "disconnecting from: %s", "loc.messages.FTPConnected": "connected: %s", + "loc.messages.InvalidFTPOptions": "There was an error when reading FTP options: %s", "loc.messages.FTPNoHostSpecified": "The FTP server URL must include a host name", "loc.messages.FTPNoProtocolSpecified": "The FTP server URL must begin with ftp:// or ftps://", "loc.messages.NoFilesFound": "Could not find any files to upload", diff --git a/Tasks/FtpUploadV2/ftpuploadtask.ts b/Tasks/FtpUploadV2/ftpuploadtask.ts index d5483ee35b28..31cddec18a44 100644 --- a/Tasks/FtpUploadV2/ftpuploadtask.ts +++ b/Tasks/FtpUploadV2/ftpuploadtask.ts @@ -261,7 +261,13 @@ async function run() { tl.setResourcePath(path.join(__dirname, "task.json")); const tries = 3; - const ftpOptions: FtpOptions = getFtpOptions(); + let ftpOptions: FtpOptions; + try { + ftpOptions = getFtpOptions(); + } catch (err) { + tl.setResult(tl.TaskResult.Failed, tl.loc('InvalidFTPOptions', err.toString())); + return; + } if (!ftpOptions.serverEndpointUrl.protocol) { tl.setResult(tl.TaskResult.Failed, tl.loc("FTPNoProtocolSpecified")); diff --git a/Tasks/FtpUploadV2/task.json b/Tasks/FtpUploadV2/task.json index c39757f985dd..9d8d7a6cadf9 100644 --- a/Tasks/FtpUploadV2/task.json +++ b/Tasks/FtpUploadV2/task.json @@ -195,6 +195,7 @@ "Disconnected": "disconnected", "DisconnectHost": "disconnecting from: %s", "FTPConnected": "connected: %s", + "InvalidFTPOptions": "There was an error when reading FTP options: %s", "FTPNoHostSpecified": "The FTP server URL must include a host name", "FTPNoProtocolSpecified": "The FTP server URL must begin with ftp:// or ftps://", "NoFilesFound": "Could not find any files to upload", @@ -203,4 +204,4 @@ "UploadSucceedRes": "FTP upload successful", "UploadFailed": "Ftp Upload failed" } -} \ No newline at end of file +} diff --git a/Tasks/FtpUploadV2/task.loc.json b/Tasks/FtpUploadV2/task.loc.json index fa15e8a556b5..d4e7b7bdc635 100644 --- a/Tasks/FtpUploadV2/task.loc.json +++ b/Tasks/FtpUploadV2/task.loc.json @@ -195,6 +195,7 @@ "Disconnected": "ms-resource:loc.messages.Disconnected", "DisconnectHost": "ms-resource:loc.messages.DisconnectHost", "FTPConnected": "ms-resource:loc.messages.FTPConnected", + "InvalidFTPOptions": "ms-resource:loc.messages.InvalidFTPOptions", "FTPNoHostSpecified": "ms-resource:loc.messages.FTPNoHostSpecified", "FTPNoProtocolSpecified": "ms-resource:loc.messages.FTPNoProtocolSpecified", "NoFilesFound": "ms-resource:loc.messages.NoFilesFound", From 11b5b8e4781924e85d33aa5f6510ade94cde09a6 Mon Sep 17 00:00:00 2001 From: DaniilShmelev Date: Thu, 15 Apr 2021 17:45:24 +0300 Subject: [PATCH 2/4] bump task version --- Tasks/FtpUploadV1/task.json | 2 +- Tasks/FtpUploadV1/task.loc.json | 2 +- Tasks/FtpUploadV2/task.json | 2 +- Tasks/FtpUploadV2/task.loc.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tasks/FtpUploadV1/task.json b/Tasks/FtpUploadV1/task.json index a37f624aa682..e22b5f70724d 100644 --- a/Tasks/FtpUploadV1/task.json +++ b/Tasks/FtpUploadV1/task.json @@ -19,7 +19,7 @@ "version": { "Major": 1, "Minor": 186, - "Patch": 0 + "Patch": 1 }, "minimumAgentVersion": "2.182.1", "instanceNameFormat": "FTP Upload: $(rootFolder)", diff --git a/Tasks/FtpUploadV1/task.loc.json b/Tasks/FtpUploadV1/task.loc.json index c3a9650f2384..76be53ee4b2b 100644 --- a/Tasks/FtpUploadV1/task.loc.json +++ b/Tasks/FtpUploadV1/task.loc.json @@ -19,7 +19,7 @@ "version": { "Major": 1, "Minor": 186, - "Patch": 0 + "Patch": 1 }, "minimumAgentVersion": "2.182.1", "instanceNameFormat": "ms-resource:loc.instanceNameFormat", diff --git a/Tasks/FtpUploadV2/task.json b/Tasks/FtpUploadV2/task.json index 9d8d7a6cadf9..d82f9c28df13 100644 --- a/Tasks/FtpUploadV2/task.json +++ b/Tasks/FtpUploadV2/task.json @@ -19,7 +19,7 @@ "version": { "Major": 2, "Minor": 186, - "Patch": 0 + "Patch": 1 }, "minimumAgentVersion": "2.182.1", "instanceNameFormat": "FTP Upload: $(rootFolder)", diff --git a/Tasks/FtpUploadV2/task.loc.json b/Tasks/FtpUploadV2/task.loc.json index d4e7b7bdc635..94abb04b546c 100644 --- a/Tasks/FtpUploadV2/task.loc.json +++ b/Tasks/FtpUploadV2/task.loc.json @@ -19,7 +19,7 @@ "version": { "Major": 2, "Minor": 186, - "Patch": 0 + "Patch": 1 }, "minimumAgentVersion": "2.182.1", "instanceNameFormat": "ms-resource:loc.instanceNameFormat", From faa4ccfbf41163fc1db5f78d46be570e38979a42 Mon Sep 17 00:00:00 2001 From: DaniilShmelev Date: Fri, 16 Apr 2021 15:39:44 +0300 Subject: [PATCH 3/4] revert FtpUploadV1 changes --- .../Strings/resources.resjson/en-US/resources.resjson | 1 - Tasks/FtpUploadV1/ftpuploadtask.ts | 11 ++--------- Tasks/FtpUploadV1/task.json | 5 ++--- Tasks/FtpUploadV1/task.loc.json | 3 +-- 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/Tasks/FtpUploadV1/Strings/resources.resjson/en-US/resources.resjson b/Tasks/FtpUploadV1/Strings/resources.resjson/en-US/resources.resjson index a20cf8bd672f..021ad3a90868 100644 --- a/Tasks/FtpUploadV1/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/FtpUploadV1/Strings/resources.resjson/en-US/resources.resjson @@ -34,7 +34,6 @@ "loc.messages.Disconnected": "disconnected", "loc.messages.DisconnectHost": "disconnecting from: %s", "loc.messages.FTPConnected": "connected: %s", - "loc.messages.InvalidFTPOptions": "There was an error when reading FTP options: %s", "loc.messages.FTPNoHostSpecified": "The FTP server URL must include a host name", "loc.messages.FTPNoProtocolSpecified": "The FTP server URL must begin with ftp:// or ftps://", "loc.messages.UploadRemoteDir": "uploading files to remote directory: %s", diff --git a/Tasks/FtpUploadV1/ftpuploadtask.ts b/Tasks/FtpUploadV1/ftpuploadtask.ts index a6e0e0d6d8d8..041bd9671d1c 100644 --- a/Tasks/FtpUploadV1/ftpuploadtask.ts +++ b/Tasks/FtpUploadV1/ftpuploadtask.ts @@ -63,14 +63,7 @@ function getFtpOptions(): FtpOptions { function doWork() { tl.setResourcePath(path.join( __dirname, 'task.json')); - let ftpOptions: FtpOptions; - try { - ftpOptions = getFtpOptions(); - } catch (err) { - tl.setResult(tl.TaskResult.Failed, tl.loc('InvalidFTPOptions', err.toString())); - return; - } - + let ftpOptions: FtpOptions = getFtpOptions(); if (!ftpOptions.serverEndpointUrl.protocol) { tl.setResult(tl.TaskResult.Failed, tl.loc('FTPNoProtocolSpecified')); } @@ -168,4 +161,4 @@ function doWork() { ftpClient.connect({ 'host': hostName, 'port': port, 'user': ftpOptions.username, 'password': ftpOptions.password, 'secure': secure, 'secureOptions': secureOptions, 'debug': debugLogger }); } -doWork(); +doWork(); \ No newline at end of file diff --git a/Tasks/FtpUploadV1/task.json b/Tasks/FtpUploadV1/task.json index e22b5f70724d..0331805eaf73 100644 --- a/Tasks/FtpUploadV1/task.json +++ b/Tasks/FtpUploadV1/task.json @@ -19,7 +19,7 @@ "version": { "Major": 1, "Minor": 186, - "Patch": 1 + "Patch": 0 }, "minimumAgentVersion": "2.182.1", "instanceNameFormat": "FTP Upload: $(rootFolder)", @@ -182,11 +182,10 @@ "Disconnected": "disconnected", "DisconnectHost": "disconnecting from: %s", "FTPConnected": "connected: %s", - "InvalidFTPOptions": "There was an error when reading FTP options: %s", "FTPNoHostSpecified": "The FTP server URL must include a host name", "FTPNoProtocolSpecified": "The FTP server URL must begin with ftp:// or ftps://", "UploadRemoteDir": "uploading files to remote directory: %s", "UploadSucceedMsg": "FTP upload successful %s", "UploadSucceedRes": "FTP upload successful" } -} +} \ No newline at end of file diff --git a/Tasks/FtpUploadV1/task.loc.json b/Tasks/FtpUploadV1/task.loc.json index 76be53ee4b2b..f3336256dc47 100644 --- a/Tasks/FtpUploadV1/task.loc.json +++ b/Tasks/FtpUploadV1/task.loc.json @@ -19,7 +19,7 @@ "version": { "Major": 1, "Minor": 186, - "Patch": 1 + "Patch": 0 }, "minimumAgentVersion": "2.182.1", "instanceNameFormat": "ms-resource:loc.instanceNameFormat", @@ -182,7 +182,6 @@ "Disconnected": "ms-resource:loc.messages.Disconnected", "DisconnectHost": "ms-resource:loc.messages.DisconnectHost", "FTPConnected": "ms-resource:loc.messages.FTPConnected", - "InvalidFTPOptions": "ms-resource:loc.messages.InvalidFTPOptions", "FTPNoHostSpecified": "ms-resource:loc.messages.FTPNoHostSpecified", "FTPNoProtocolSpecified": "ms-resource:loc.messages.FTPNoProtocolSpecified", "UploadRemoteDir": "ms-resource:loc.messages.UploadRemoteDir", From c1b7c8f8855f2553b5be00214aa8c2283a00cce0 Mon Sep 17 00:00:00 2001 From: DaniilShmelev Date: Fri, 16 Apr 2021 19:10:56 +0300 Subject: [PATCH 4/4] fix automatic string conversion --- Tasks/FtpUploadV2/ftpuploadtask.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/FtpUploadV2/ftpuploadtask.ts b/Tasks/FtpUploadV2/ftpuploadtask.ts index 31cddec18a44..1469c5ce0856 100644 --- a/Tasks/FtpUploadV2/ftpuploadtask.ts +++ b/Tasks/FtpUploadV2/ftpuploadtask.ts @@ -265,7 +265,7 @@ async function run() { try { ftpOptions = getFtpOptions(); } catch (err) { - tl.setResult(tl.TaskResult.Failed, tl.loc('InvalidFTPOptions', err.toString())); + tl.setResult(tl.TaskResult.Failed, tl.loc('InvalidFTPOptions', err)); return; }