Skip to content

Commit 957b831

Browse files
committed
Use error messages in TransferException's InnerException for that DMLib wrappers the exception without exposing any detailed error messages.
1 parent d639661 commit 957b831

10 files changed

+95
-76
lines changed

src/Common/Storage/Commands.Storage/Blob/Cmdlet/GetAzureStorageBlobContent.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ internal virtual async Task DownloadBlob(long taskId, IStorageBlobManagement loc
132132
TotalSize = blob.Properties.Length
133133
};
134134

135-
await this.DoTransfer(() =>
135+
await DataMovementTransferHelper.DoTransfer(() =>
136136
{
137137
return this.TransferManager.DownloadAsync(blob, filePath,
138138
new DownloadOptions()
@@ -141,7 +141,9 @@ await this.DoTransfer(() =>
141141
},
142142
this.GetTransferContext(data),
143143
this.CmdletCancellationToken);
144-
}, data);
144+
},
145+
data.Record,
146+
this.OutputStream);
145147

146148
this.WriteCloudBlobObject(data.TaskId, data.Channel, blob);
147149
}

src/Common/Storage/Commands.Storage/Blob/Cmdlet/SetAzureStorageBlobContent.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,16 @@ internal virtual async Task Upload2Blob(long taskId, IStorageBlobManagement loca
195195
TotalSize = fileInfo.Length
196196
};
197197

198-
await this.DoTransfer(() =>
198+
await DataMovementTransferHelper.DoTransfer(() =>
199199
{
200200
return this.TransferManager.UploadAsync(filePath,
201201
blob,
202202
null,
203203
this.GetTransferContext(data),
204204
this.CmdletCancellationToken);
205-
}, data);
205+
},
206+
data.Record,
207+
this.OutputStream);
206208

207209
if (this.BlobProperties != null || this.BlobMetadata != null)
208210
{

src/Common/Storage/Commands.Storage/Blob/StorageCloudBlobCmdletBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ namespace Microsoft.WindowsAzure.Commands.Storage
1616
{
1717
using System;
1818
using System.Globalization;
19+
using System.Management.Automation;
20+
using System.Threading.Tasks;
1921
using Microsoft.WindowsAzure.Commands.Common.Storage;
22+
using Microsoft.WindowsAzure.Commands.Storage.Blob;
2023
using Microsoft.WindowsAzure.Commands.Storage.Common;
2124
using Microsoft.WindowsAzure.Commands.Storage.Model.Contract;
2225
using Microsoft.WindowsAzure.Commands.Storage.Model.ResourceModel;
2326
using Microsoft.WindowsAzure.Storage;
2427
using Microsoft.WindowsAzure.Storage.Blob;
28+
using Microsoft.WindowsAzure.Storage.DataMovement;
2529

2630
/// <summary>
2731
/// Base cmdlet for storage blob/container cmdlet
@@ -216,5 +220,6 @@ protected void ValidateBlobType(CloudBlob blob)
216220
blob.Name));
217221
}
218222
}
223+
219224
}
220225
}

src/Common/Storage/Commands.Storage/Blob/StorageDataMovementCmdletBase.cs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Blob
1919
using System.Management.Automation;
2020
using System.Threading.Tasks;
2121
using Microsoft.WindowsAzure.Commands.Storage.Common;
22+
using Microsoft.WindowsAzure.Storage;
2223
using Microsoft.WindowsAzure.Storage.Blob;
2324
using Microsoft.WindowsAzure.Storage.DataMovement;
2425

@@ -71,39 +72,6 @@ protected override void BeginProcessing()
7172
this.TransferManager = TransferManagerFactory.CreateTransferManager(this.GetCmdletConcurrency());
7273
}
7374

74-
protected async Task DoTransfer(Func<Task> doTransfer, DataMovementUserData userData)
75-
{
76-
try
77-
{
78-
await doTransfer();
79-
80-
if (userData.Record != null)
81-
{
82-
userData.Record.PercentComplete = 100;
83-
userData.Record.StatusDescription = Resources.TransmitSuccessfully;
84-
this.OutputStream.WriteProgress(userData.Record);
85-
}
86-
}
87-
catch (OperationCanceledException)
88-
{
89-
if (userData.Record != null)
90-
{
91-
userData.Record.StatusDescription = Resources.TransmitCancelled;
92-
this.OutputStream.WriteProgress(userData.Record);
93-
}
94-
}
95-
catch (Exception e)
96-
{
97-
if (userData.Record != null)
98-
{
99-
userData.Record.StatusDescription = string.Format(CultureInfo.CurrentCulture, Resources.TransmitFailed, e.Message);
100-
this.OutputStream.WriteProgress(userData.Record);
101-
}
102-
103-
throw;
104-
}
105-
}
106-
10775
protected TransferContext GetTransferContext(DataMovementUserData userData)
10876
{
10977
TransferContext transferContext = new TransferContext();

src/Common/Storage/Commands.Storage/Commands.Storage.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
</Reference>
108108
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
109109
<SpecificVersion>False</SpecificVersion>
110-
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.2.0.0.0\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>
110+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.2.0.3\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>
111111
</Reference>
112112
<Reference Include="Microsoft.WindowsAzure.Management">
113113
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
@@ -190,6 +190,7 @@
190190
<Compile Include="Common\Cmdlet\SetAzureStorageServiceMetrics.cs" />
191191
<Compile Include="Common\ConfirmTaskCompletionSource.cs" />
192192
<Compile Include="Common\DataManagementWrapper.cs" />
193+
<Compile Include="Common\DataMovementTransferHelper.cs" />
193194
<Compile Include="Common\ITransferManager.cs" />
194195
<Compile Include="Common\LimitedConcurrencyTaskScheduler.cs" />
195196
<Compile Include="Common\NameUtil.cs" />
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Management.Automation;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using Microsoft.WindowsAzure.Storage;
9+
using Microsoft.WindowsAzure.Storage.DataMovement;
10+
11+
namespace Microsoft.WindowsAzure.Commands.Storage.Common
12+
{
13+
internal class DataMovementTransferHelper
14+
{
15+
static public async Task DoTransfer(Func<Task> doTransfer, ProgressRecord record, TaskOutputStream outputStream)
16+
{
17+
try
18+
{
19+
await doTransfer();
20+
21+
if (record != null)
22+
{
23+
record.PercentComplete = 100;
24+
record.StatusDescription = Resources.TransmitSuccessfully;
25+
outputStream.WriteProgress(record);
26+
}
27+
}
28+
catch (OperationCanceledException)
29+
{
30+
if (record != null)
31+
{
32+
record.StatusDescription = Resources.TransmitCancelled;
33+
outputStream.WriteProgress(record);
34+
}
35+
}
36+
catch (TransferException e)
37+
{
38+
// DMLib wrappers StorageException in its InnerException but didn't expose any detailed error messages,
39+
// here throw its inner exception out to show more readable error messages.
40+
StorageException se = e.InnerException as StorageException;
41+
42+
if (null != se)
43+
{
44+
HandleTransferException(se, record, outputStream);
45+
throw se;
46+
}
47+
else
48+
{
49+
HandleTransferException(e, record, outputStream);
50+
throw;
51+
}
52+
}
53+
catch (Exception e)
54+
{
55+
HandleTransferException(e, record, outputStream);
56+
throw;
57+
}
58+
}
59+
60+
static private void HandleTransferException(Exception e, ProgressRecord record, TaskOutputStream outputStream)
61+
{
62+
if (record != null)
63+
{
64+
record.StatusDescription = string.Format(CultureInfo.CurrentCulture, Resources.TransmitFailed, e.Message);
65+
outputStream.WriteProgress(record);
66+
}
67+
}
68+
}
69+
}

src/Common/Storage/Commands.Storage/File/Cmdlet/GetAzureStorageFileContent.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
namespace Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet
2121
{
22+
using Microsoft.WindowsAzure.Commands.Storage.Common;
2223
using Microsoft.WindowsAzure.Storage.DataMovement;
2324
using LocalConstants = Microsoft.WindowsAzure.Commands.Storage.File.Constants;
2425
using LocalDirectory = System.IO.Directory;
@@ -158,7 +159,7 @@ public override void ExecuteCmdlet()
158159
string.Format(CultureInfo.CurrentCulture, Resources.ReceiveAzureFileActivity, fileToBeDownloaded.GetFullPath(), targetFile),
159160
Resources.PrepareDownloadingFile);
160161

161-
await this.DoTransfer(() =>
162+
await DataMovementTransferHelper.DoTransfer(() =>
162163
{
163164
return this.TransferManager.DownloadAsync(
164165
fileToBeDownloaded,
@@ -167,7 +168,8 @@ await this.DoTransfer(() =>
167168
this.GetTransferContext(progressRecord, fileToBeDownloaded.Properties.Length),
168169
CmdletCancellationToken);
169170
},
170-
progressRecord);
171+
progressRecord,
172+
this.OutputStream);
171173

172174
if (this.PassThru)
173175
{

src/Common/Storage/Commands.Storage/File/Cmdlet/SetAzureStorageFileContent.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet
1919
using System.Management.Automation;
2020
using System.Net;
2121
using System.Threading.Tasks;
22+
using Microsoft.WindowsAzure.Commands.Storage.Common;
2223
using Microsoft.WindowsAzure.Storage;
2324
using Microsoft.WindowsAzure.Storage.DataMovement;
2425
using Microsoft.WindowsAzure.Storage.File;
@@ -93,7 +94,7 @@ public override void ExecuteCmdlet()
9394
string.Format(CultureInfo.CurrentCulture, Resources.SendAzureFileActivity, localFile.Name, cloudFileToBeUploaded.GetFullPath(), cloudFileToBeUploaded.Share.Name),
9495
Resources.PrepareUploadingFile);
9596

96-
await this.DoTransfer(() =>
97+
await DataMovementTransferHelper.DoTransfer(() =>
9798
{
9899
return this.TransferManager.UploadAsync(
99100
localFile.FullName,
@@ -102,7 +103,8 @@ await this.DoTransfer(() =>
102103
this.GetTransferContext(progressRecord, localFile.Length),
103104
this.CmdletCancellationToken);
104105
},
105-
progressRecord);
106+
progressRecord,
107+
this.OutputStream);
106108

107109

108110
if (this.PassThru)

src/Common/Storage/Commands.Storage/File/StorageFileDataManagementCmdletBase.cs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.File
2020
using System.Threading.Tasks;
2121
using Microsoft.WindowsAzure.Commands.Storage.Blob;
2222
using Microsoft.WindowsAzure.Commands.Storage.Common;
23+
using Microsoft.WindowsAzure.Storage;
2324
using Microsoft.WindowsAzure.Storage.DataMovement;
2425
using Microsoft.WindowsAzure.Storage.File;
2526

@@ -80,39 +81,6 @@ protected override void EndProcessing()
8081
}
8182
}
8283

83-
protected async Task DoTransfer(Func<Task> doTransfer, ProgressRecord record)
84-
{
85-
try
86-
{
87-
await doTransfer();
88-
89-
if (record != null)
90-
{
91-
record.PercentComplete = 100;
92-
record.StatusDescription = Resources.TransmitSuccessfully;
93-
this.OutputStream.WriteProgress(record);
94-
}
95-
}
96-
catch (OperationCanceledException)
97-
{
98-
if (record != null)
99-
{
100-
record.StatusDescription = Resources.TransmitCancelled;
101-
this.OutputStream.WriteProgress(record);
102-
}
103-
}
104-
catch (Exception e)
105-
{
106-
if (record != null)
107-
{
108-
record.StatusDescription = string.Format(CultureInfo.CurrentCulture, Resources.TransmitFailed, e.Message);
109-
this.OutputStream.WriteProgress(record);
110-
}
111-
112-
throw;
113-
}
114-
}
115-
11684
protected TransferContext GetTransferContext(ProgressRecord record, long totalTransferLength)
11785
{
11886
TransferContext transferContext = new TransferContext();

src/Common/Storage/Commands.Storage/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" />
1818
<package id="Microsoft.Rest.ClientRuntime" version="1.8.2" targetFramework="net45" />
1919
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="0.11.0" targetFramework="net45" />
20-
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.0.0" targetFramework="net45" />
20+
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net45" />
2121
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
2222
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
2323
<package id="System.Spatial" version="5.6.4" targetFramework="net45" />

0 commit comments

Comments
 (0)