Skip to content

Commit cb9f8ec

Browse files
committed
Fix error handling in device jobs related cmdlets
1 parent af86129 commit cb9f8ec

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/DeviceJobs/GetAzureStorSimpleJob.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,7 @@ public override void ExecuteCmdlet()
103103
try
104104
{
105105
// Make sure params were supplied appropriately.
106-
if (!ProcessParameters())
107-
{
108-
return;
109-
}
106+
ProcessParameters();
110107

111108
// Make call to get device jobs.
112109
var response = StorSimpleClient.GetDeviceJobs(deviceId, Type, Status, InstanceId, fromDateTimeIsoString, toDateTimeIsoString, (int)Skip, (int)First);
@@ -115,9 +112,7 @@ public override void ExecuteCmdlet()
115112
{
116113
if (response == null || response.DeviceJobList.Count < 1)
117114
{
118-
WriteVerbose(string.Format(Resources.NoDeviceJobFoundWithGivenIdMessage, InstanceId));
119-
WriteObject(null);
120-
return;
115+
throw new ArgumentException(string.Format(Resources.NoDeviceJobFoundWithGivenIdMessage, InstanceId));
121116
}
122117
WriteObject(response.DeviceJobList.First());
123118
return;
@@ -174,13 +169,9 @@ private bool ProcessParameters()
174169
deviceId = StorSimpleClient.GetDeviceId(DeviceName);
175170
if (deviceId == null)
176171
{
177-
WriteVerbose(string.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage,StorSimpleContext.ResourceName, DeviceName));
178-
WriteObject(null);
179-
return false;
172+
throw new ArgumentException(string.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage,StorSimpleContext.ResourceName, DeviceName));
180173
}
181174
}
182-
183-
return true;
184175
}
185176
}
186177
}

src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/DeviceJobs/StopAzureStorSimpleJob.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,13 @@ public override void ExecuteCmdlet()
5757
var deviceJobDetails = StorSimpleClient.GetDeviceJobById(InstanceId);
5858
if (deviceJobDetails == null)
5959
{
60-
WriteVerbose(string.Format(Resources.NoDeviceJobFoundWithGivenIdMessage, InstanceId));
61-
WriteObject(null);
62-
return;
60+
throw new ArgumentException(string.Format(Resources.NoDeviceJobFoundWithGivenIdMessage, InstanceId))
6361
}
6462

6563
// Make sure the job is running and cancellable, else fail.
6664
if (!(deviceJobDetails.IsJobCancellable && deviceJobDetails.Status == "Running"))
6765
{
68-
WriteVerbose(string.Format(Resources.JobNotRunningOrCancellable, InstanceId));
69-
WriteObject(null);
70-
return;
66+
throw new ArgumentException(string.Format(Resources.JobNotRunningOrCancellable, InstanceId));
7167
}
7268

7369
// issue call to cancel the job.

0 commit comments

Comments
 (0)