Skip to content

Commit 69ef62d

Browse files
committed
Merge pull request Azure#1350 from jianghaolu/dstream
[Fixes #108813328] Turn on debug stream when terminating error is thrown
2 parents e2ff4fb + 6cd22c5 commit 69ef62d

File tree

5 files changed

+94
-1
lines changed

5 files changed

+94
-1
lines changed

src/Common/Commands.Common/AzurePSCmdlet.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public abstract class AzurePSCmdlet : PSCmdlet, IDisposable
3838
protected readonly ConcurrentQueue<string> _debugMessages;
3939

4040
private RecordingTracingInterceptor _httpTracingInterceptor;
41-
41+
4242
private DebugStreamTraceListener _adalListener;
4343
protected static AzurePSDataCollectionProfile _dataCollectionProfile = null;
4444
protected static string _errorRecordFolderPath = null;
@@ -272,6 +272,12 @@ protected bool IsVerbose()
272272
base.WriteError(errorRecord);
273273
}
274274

275+
protected new void ThrowTerminatingError(ErrorRecord errorRecord)
276+
{
277+
FlushDebugMessages(IsDataCollectionAllowed());
278+
base.ThrowTerminatingError(errorRecord);
279+
}
280+
275281
protected new void WriteObject(object sendToPipeline)
276282
{
277283
FlushDebugMessages();
@@ -515,6 +521,11 @@ protected virtual void Dispose(bool disposing)
515521

516522
public void Dispose()
517523
{
524+
try
525+
{
526+
FlushDebugMessages();
527+
}
528+
catch { }
518529
Dispose(true);
519530
GC.SuppressFinalize(this);
520531
}

src/ResourceManager/Resources/Commands.Resources.Test/Commands.Resources.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@
351351
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceGroupTests\TestFindResourceGroup.json">
352352
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
353353
</None>
354+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceGroupTests\TestGetNonExistingResourceGroupWithDebugStream.json">
355+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
356+
</None>
354357
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceGroupTests\TestNewDeploymentAndProviderRegistration.json">
355358
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
356359
</None>

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ResourceGroupTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,11 @@ public void TestRemoveDeployment()
8787
{
8888
ResourcesController.NewInstance.RunPsTest("Test-RemoveDeployment");
8989
}
90+
91+
[Fact]
92+
public void TestGetNonExistingResourceGroupWithDebugStream()
93+
{
94+
ResourcesController.NewInstance.RunPsTest("Test-GetNonExistingResourceGroupWithDebugStream");
95+
}
9096
}
9197
}

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ResourceGroupTests.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,16 @@ function Test-FindResourceGroup
305305
Clean-ResourceGroup $rgname
306306
Clean-ResourceGroup $rgname2
307307
}
308+
}
309+
310+
<#
311+
.SYNOPSIS
312+
Tests remove non exist resource group and debug stream gets printed
313+
#>
314+
function Test-GetNonExistingResourceGroupWithDebugStream
315+
{
316+
$ErrorActionPreference="Continue"
317+
$output = $(Get-AzureRmResourceGroup -Name "InvalidNonExistRocks" -Debug) 2>&1 5>&1 | Out-String
318+
$ErrorActionPreference="Stop"
319+
Assert-True { $output -Like "*============================ HTTP RESPONSE ============================*" }
308320
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "/subscriptions/3ca49042-782a-4cc9-89b5-ee1b487fe115/resourcegroups/InvalidNonExistRocks?api-version=2014-04-01-preview",
5+
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvM2NhNDkwNDItNzgyYS00Y2M5LTg5YjUtZWUxYjQ4N2ZlMTE1L3Jlc291cmNlZ3JvdXBzL0ludmFsaWROb25FeGlzdFJvY2tzP2FwaS12ZXJzaW9uPTIwMTQtMDQtMDEtcHJldmlldw==",
6+
"RequestMethod": "GET",
7+
"RequestBody": "",
8+
"RequestHeaders": {
9+
"User-Agent": [
10+
"Microsoft.Azure.Management.Resources.ResourceManagementClient/2.0.0.0"
11+
]
12+
},
13+
"ResponseBody": "{\r\n \"error\": {\r\n \"code\": \"ResourceGroupNotFound\",\r\n \"message\": \"Resource group 'InvalidNonExistRocks' could not be found.\"\r\n }\r\n}",
14+
"ResponseHeaders": {
15+
"Content-Length": [
16+
"112"
17+
],
18+
"Content-Type": [
19+
"application/json; charset=utf-8"
20+
],
21+
"Expires": [
22+
"-1"
23+
],
24+
"Pragma": [
25+
"no-cache"
26+
],
27+
"x-ms-failure-cause": [
28+
"gateway"
29+
],
30+
"x-ms-ratelimit-remaining-subscription-reads": [
31+
"14999"
32+
],
33+
"x-ms-request-id": [
34+
"3633e6fd-16ca-4f0d-830f-bfa2eacf42f9"
35+
],
36+
"x-ms-correlation-request-id": [
37+
"3633e6fd-16ca-4f0d-830f-bfa2eacf42f9"
38+
],
39+
"x-ms-routing-request-id": [
40+
"WESTUS:20151125T215815Z:3633e6fd-16ca-4f0d-830f-bfa2eacf42f9"
41+
],
42+
"Strict-Transport-Security": [
43+
"max-age=31536000; includeSubDomains"
44+
],
45+
"Cache-Control": [
46+
"no-cache"
47+
],
48+
"Date": [
49+
"Wed, 25 Nov 2015 21:58:14 GMT"
50+
]
51+
},
52+
"StatusCode": 404
53+
}
54+
],
55+
"Names": {},
56+
"Variables": {
57+
"SubscriptionId": "3ca49042-782a-4cc9-89b5-ee1b487fe115",
58+
"TenantId": "1449d5b7-8a83-47db-ae4c-9b03e888bad0",
59+
"Domain": "rbactest.onmicrosoft.com"
60+
}
61+
}

0 commit comments

Comments
 (0)