Skip to content

Commit

Permalink
Improve Error Handling
Browse files Browse the repository at this point in the history
Provide more informative errror output and use non-terminating exceptions. Related to Issue #138
  • Loading branch information
McGlovin1337 committed Nov 5, 2021
1 parent 6181012 commit 5c0ede9
Show file tree
Hide file tree
Showing 8 changed files with 318 additions and 192 deletions.
26 changes: 21 additions & 5 deletions PSAsigraDSClient/GetDSClientBackupSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,29 @@ sealed public class GetDSClientBackupSet: BaseDSClientBackupSet

protected override void DSClientProcessRecord()
{
WriteVerbose($"Performing Action: Retrieve Backup Set with BackupSetId: {BackupSetId}");
BackupSet backupSet = DSClientSession.backup_set(BackupSetId);
BackupSet backupSet = null;
try
{
WriteVerbose($"Performing Action: Retrieve Backup Set with BackupSetId: {BackupSetId}");
backupSet = DSClientSession.backup_set(BackupSetId);
}
catch (APIException e)
{
ErrorRecord errorRecord = new ErrorRecord(
e,
"APIException",
ErrorCategory.ObjectNotFound,
null);
WriteError(errorRecord);
}

WriteDebug("Parsing Backup Set details.");
DSClientBackupSet dSClientBackupSet = new DSClientBackupSet(backupSet, DSClientSessionInfo.OperatingSystem);
if (backupSet != null)
{
WriteDebug("Parsing Backup Set details.");
DSClientBackupSet dSClientBackupSet = new DSClientBackupSet(backupSet, DSClientSessionInfo.OperatingSystem);

WriteObject(dSClientBackupSet);
WriteObject(dSClientBackupSet);
}
}
}
}
51 changes: 34 additions & 17 deletions PSAsigraDSClient/GetDSClientBackupSetItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,41 @@ sealed public class GetDSClientBackupSetItem: BaseDSClientBackupSet

protected override void DSClientProcessRecord()
{
// Get the specified Backup Set
WriteVerbose($"Performing Action: Retrieve Backup Set with BackupSetId: {BackupSetId}");
BackupSet backupSet = DSClientSession.backup_set(BackupSetId);

// Get the Data Type this Backup Set contains
EBackupDataType backupDataType = backupSet.getDataType();

// Get the Backup Set Items specified in the Backup Set
BackupSetItem[] backupSetItems = backupSet.items();

List<DSClientBackupSetItem> dSClientBackupSetItems = new List<DSClientBackupSetItem>();
BackupSet backupSet = null;

foreach (BackupSetItem item in backupSetItems)
dSClientBackupSetItems.Add(new DSClientBackupSetItem(item, backupDataType, DSClientSessionInfo.OperatingSystem));

dSClientBackupSetItems.ForEach(WriteObject);

backupSet.Dispose();
// Get the specified Backup Set
try
{
WriteVerbose($"Performing Action: Retrieve Backup Set with BackupSetId: {BackupSetId}");
backupSet = DSClientSession.backup_set(BackupSetId);
}
catch (APIException e)
{
ErrorRecord errorRecord = new ErrorRecord(
e,
"APIException",
ErrorCategory.ObjectNotFound,
null);
WriteError(errorRecord);
}

if (backupSet != null)
{
// Get the Data Type this Backup Set contains
EBackupDataType backupDataType = backupSet.getDataType();

// Get the Backup Set Items specified in the Backup Set
BackupSetItem[] backupSetItems = backupSet.items();

List<DSClientBackupSetItem> dSClientBackupSetItems = new List<DSClientBackupSetItem>();

foreach (BackupSetItem item in backupSetItems)
dSClientBackupSetItems.Add(new DSClientBackupSetItem(item, backupDataType, DSClientSessionInfo.OperatingSystem));

dSClientBackupSetItems.ForEach(WriteObject);

backupSet.Dispose();
}
}
}
}
30 changes: 24 additions & 6 deletions PSAsigraDSClient/GetDSClientBackupSetLockStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,35 @@ sealed public class GetDSClientBackupSetLockStatus : DSClientCmdlet

protected override void DSClientProcessRecord()
{
BackupSet backupSet = null;

// Retrieve the Backup Set
BackupSet backupSet = DSClientSession.backup_set(BackupSetId);
try
{
WriteVerbose($"Performing Action: Retrieve Backup Set with BackupSetId: {BackupSetId}");
backupSet = DSClientSession.backup_set(BackupSetId);
}
catch (APIException e)
{
ErrorRecord errorRecord = new ErrorRecord(
e,
"APIException",
ErrorCategory.ObjectNotFound,
null);
WriteError(errorRecord);
}

// Activity Type
EActivityType activityType = StringToEnum<EActivityType>(ActivityType);
if (backupSet != null)
{
// Activity Type
EActivityType activityType = StringToEnum<EActivityType>(ActivityType);

EBackupSetLockStatus setLockStatus = backupSet.check_lock_status(activityType);
EBackupSetLockStatus setLockStatus = backupSet.check_lock_status(activityType);

backupSet.Dispose();
backupSet.Dispose();

WriteObject(new BackupSetLockStatus(setLockStatus));
WriteObject(new BackupSetLockStatus(setLockStatus));
}
}

private class BackupSetLockStatus
Expand Down
52 changes: 35 additions & 17 deletions PSAsigraDSClient/GetDSClientBackupSetNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,41 @@ sealed public class GetDSClientBackupSetNotification : DSClientCmdlet

protected override void DSClientProcessRecord()
{
WriteVerbose("Performing Action: Retrieve Backup Set");
BackupSet backupSet = DSClientSession.backup_set(BackupSetId);

BackupSetNotification backupSetNotification = backupSet.getNotification();

WriteVerbose("Performing Action: Retrieve Backup Set Notification Configuration");
notification_info[] notifications = backupSetNotification.listNotification();

backupSetNotification.Dispose();
backupSet.Dispose();

List<DSClientBackupSetNotification> backupSetNotifications = new List<DSClientBackupSetNotification>();

foreach (notification_info notification in notifications)
backupSetNotifications.Add(new DSClientBackupSetNotification(notification));

backupSetNotifications.ForEach(WriteObject);
BackupSet backupSet = null;

// Retrieve the Backup Set
try
{
WriteVerbose($"Performing Action: Retrieve Backup Set with BackupSetId: {BackupSetId}");
backupSet = DSClientSession.backup_set(BackupSetId);
}
catch (APIException e)
{
ErrorRecord errorRecord = new ErrorRecord(
e,
"APIException",
ErrorCategory.ObjectNotFound,
null);
WriteError(errorRecord);
}

if (backupSet != null)
{
BackupSetNotification backupSetNotification = backupSet.getNotification();

WriteVerbose("Performing Action: Retrieve Backup Set Notification Configuration");
notification_info[] notifications = backupSetNotification.listNotification();

backupSetNotification.Dispose();
backupSet.Dispose();

List<DSClientBackupSetNotification> backupSetNotifications = new List<DSClientBackupSetNotification>();

foreach (notification_info notification in notifications)
backupSetNotifications.Add(new DSClientBackupSetNotification(notification));

backupSetNotifications.ForEach(WriteObject);
}
}
}
}
42 changes: 30 additions & 12 deletions PSAsigraDSClient/GetDSClientBackupSetSessions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,41 @@ sealed public class GetDSClientBackupSetSessions: DSClientCmdlet

protected override void DSClientProcessRecord()
{
List<DSClientBackupSessions> BackupSessions = new List<DSClientBackupSessions>();
BackupSet backupSet = null;

WriteVerbose($"Performing Action: Retrieve Backup Set with BackupSetId: {BackupSetId}");
BackupSet backupSet = DSClientSession.backup_set(BackupSetId);

WriteVerbose("Performing Action: Retrieve Backup Set Sessions");
backup_sessions[] backupSessions = backupSet.backup_times();

foreach (backup_sessions session in backupSessions)
// Retrieve the Backup Set
try
{
DSClientBackupSessions backupSession = new DSClientBackupSessions(BackupSetId, session);
BackupSessions.Add(backupSession);
WriteVerbose($"Performing Action: Retrieve Backup Set with BackupSetId: {BackupSetId}");
backupSet = DSClientSession.backup_set(BackupSetId);
}
catch (APIException e)
{
ErrorRecord errorRecord = new ErrorRecord(
e,
"APIException",
ErrorCategory.ObjectNotFound,
null);
WriteError(errorRecord);
}

BackupSessions.ForEach(WriteObject);
if (backupSet != null)
{
List<DSClientBackupSessions> BackupSessions = new List<DSClientBackupSessions>();

backupSet.Dispose();
WriteVerbose("Performing Action: Retrieve Backup Set Sessions");
backup_sessions[] backupSessions = backupSet.backup_times();

foreach (backup_sessions session in backupSessions)
{
DSClientBackupSessions backupSession = new DSClientBackupSessions(BackupSetId, session);
BackupSessions.Add(backupSession);
}

BackupSessions.ForEach(WriteObject);

backupSet.Dispose();
}
}

private class DSClientBackupSessions
Expand Down
18 changes: 15 additions & 3 deletions PSAsigraDSClient/GetDSClientRetentionRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,21 @@ protected override void ProcessRetentionRule(RetentionRule[] dSClientRetentionRu
{
if (RetentionRuleId > 0)
{
RetentionRule retentionRule = dSClientRetentionRules.Single(rule => rule.getID() == RetentionRuleId);
DSClientRetentionRule dSClientRetentionRule = new DSClientRetentionRule(retentionRule);
DSClientRetentionRules.Add(dSClientRetentionRule);
try
{
RetentionRule retentionRule = dSClientRetentionRules.Single(rule => rule.getID() == RetentionRuleId);
DSClientRetentionRule dSClientRetentionRule = new DSClientRetentionRule(retentionRule);
DSClientRetentionRules.Add(dSClientRetentionRule);
}
catch
{
ErrorRecord errorRecord = new ErrorRecord(
new Exception("Retention Rule not found"),
"Exception",
ErrorCategory.ObjectNotFound,
null);
WriteError(errorRecord);
}
}

if (Name != null)
Expand Down
Loading

0 comments on commit 5c0ede9

Please sign in to comment.