-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Changes from 1 commit
b341b78
72f2b06
9f82a74
15c9955
9f89647
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -664,7 +664,9 @@ function Add-AzureSqlDatabaseServerFirewallRule | |
$parsedException = Parse-Exception($_.Exception) | ||
if($parsedException) | ||
{ | ||
throw $parsedException | ||
Write-Verbose $parsedException | ||
$exception = $parsedException | ConvertFrom-Json | ||
throw $exception.Message | ||
} | ||
throw $_.Exception.ToString() | ||
} | ||
|
@@ -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() | ||
} | ||
|
@@ -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){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
"version": { | ||
"Major": 1, | ||
"Minor": 1, | ||
"Patch": 3 | ||
"Patch": 4 | ||
}, | ||
"demands": [ | ||
"sqlpackage" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
"version": { | ||
"Major": 1, | ||
"Minor": 1, | ||
"Patch": 3 | ||
"Patch": 4 | ||
}, | ||
"demands": [ | ||
"sqlpackage" | ||
|
There was a problem hiding this comment.
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.