Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve sql azure deployment task errors handling #3263

Merged
merged 5 commits into from
Dec 22, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Tasks/Common/VstsAzureRestHelpers_/VstsAzureRestHelpers_.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,9 @@ function Add-AzureSqlDatabaseServerFirewallRule
$parsedException = Parse-Exception($_.Exception)
if($parsedException)
{
throw $parsedException
Write-Verbose $parsedException
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be within Parse-Exception.

$exception = $parsedException | ConvertFrom-Json
throw $exception.Message
}
throw $_.Exception.ToString()
}
Expand Down Expand Up @@ -705,7 +707,9 @@ function Remove-AzureSqlDatabaseServerFirewallRule
$parsedException = Parse-Exception($_.Exception)
if($parsedException)
{
throw $parsedException
Write-Verbose $parsedException
$exception = $parsedException | ConvertFrom-Json
throw $exception.Message
}
throw $_.Exception.ToString()
}
Expand All @@ -722,6 +726,9 @@ function Parse-Exception($exception){
$responseBody = $streamReader.ReadToEnd()
$streamReader.Close()
Write-Verbose "Exception message extracted from response $responseBody"
if($response.statusCode -eq 404){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do/Should We need to handle any othe rcase here like 500 etc ?

Write-Warning "Please verify request URL : $($response.ResponseUri)"
}
return $responseBody
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tasks/SqlAzureDacpacDeployment/DeploySqlAzure.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ Catch [System.Management.Automation.CommandNotFoundException]
Write-Host "3. Run Import-Module SQLPS on your agent Powershell prompt. (This step is not required on Powershell 3.0 enabled machines)"
}

Write-Error ($_.Exception|Format-List -Force|Out-String)
Write-Error ($_.Exception.Message)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do like this - if exception.Message is not null and empty then write error.message but it is empty or null write full exception

throw
}
Catch [Exception]
{
Write-Error ($_.Exception|Format-List -Force|Out-String)
Write-Error ($_.Exception.Message)
throw
}
Finally
Expand Down
31 changes: 16 additions & 15 deletions Tasks/SqlAzureDacpacDeployment/Utility.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -187,24 +187,25 @@ function Get-SqlPackageCommandArguments

function Run-Command
{
param([String][Parameter(Mandatory=$true)] $command)

try
{
if( $psversiontable.PSVersion.Major -le 4)
{
cmd.exe /c "`"$command`"" 2>&1
}
else
{
cmd.exe /c "$command" 2>&1
}

param(
[string]$command,
[bool] $failOnErr = $true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit pick - we can have verbose name like failOnError

)
$ErrorActionPreference = 'Continue'
if( $psversiontable.PSVersion.Major -le 4)
{
$result = cmd.exe /c "`"$command`"" 2>&1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using the task lib tool runner for this.

}
catch [System.Exception]
else
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If some Exception is raised here , We wont be returning result or exception trace in that case, right ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anything during execution of command fails it will come as part of result.

$result = cmd.exe /c "$command" 2>&1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Use task lib.

}
$ErrorActionPreference = 'Stop'
if($failOnErr -and $LASTEXITCODE -ne 0)
{
throw $_.Exception
throw $result
}
return $result
}

function ConvertParamToSqlSupported
Expand Down
2 changes: 1 addition & 1 deletion Tasks/SqlAzureDacpacDeployment/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 1,
"Patch": 3
"Patch": 4
},
"demands": [
"sqlpackage"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/SqlAzureDacpacDeployment/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 1,
"Patch": 3
"Patch": 4
},
"demands": [
"sqlpackage"
Expand Down