Skip to content

Commit 7caa53c

Browse files
fix(migration): Honor SilentlyContinue in Get-DbaCmObject StopFunction calls
Add IsSilentContinue property that computes the effective isContinue value matching PS1 Stop-Function semantics: when EnableException is true and SilentlyContinue is false, errors are terminating; otherwise flow continues. All connection-related StopFunction calls now use this instead of hardcoded true. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent af8a282 commit 7caa53c

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

project/dbatools/Commands/GetDbaCmObjectCommand.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ public class GetDbaCmObjectCommand : DbaBaseCmdlet
7777
/// </summary>
7878
private string _parameterSetName;
7979

80+
/// <summary>
81+
/// Computes the effective isContinue value for StopFunction calls that pass -SilentlyContinue.
82+
/// In PS1, when EnableException is true and SilentlyContinue is false, Stop-Function throws
83+
/// (ignoring -Continue). When SilentlyContinue is true, it writes a non-terminating error
84+
/// and continues. When EnableException is false, -Continue always controls the flow.
85+
/// </summary>
86+
private bool IsSilentContinue
87+
{
88+
get { return !EnableException.ToBool() || SilentlyContinue.IsPresent; }
89+
}
90+
8091
/// <summary>
8192
/// Initializes the cmdlet, reads configuration values.
8293
/// </summary>
@@ -111,7 +122,7 @@ protected override void ProcessRecord()
111122
String.Format("Failed to interpret input: {0}", connectionObject.InputObject),
112123
category: ErrorCategory.InvalidArgument,
113124
target: connectionObject.InputObject,
114-
isContinue: true);
125+
isContinue: IsSilentContinue);
115126
TestFunctionInterrupt();
116127
continue;
117128
}
@@ -210,7 +221,7 @@ protected override void ProcessRecord()
210221
computer, enabledProtocols),
211222
errorRecord: new ErrorRecord(ex, "NoConnection", ErrorCategory.OpenError, computer),
212223
target: computer,
213-
isContinue: true);
224+
isContinue: IsSilentContinue);
214225
TestFunctionInterrupt();
215226
break;
216227
}
@@ -288,7 +299,7 @@ private bool ProcessCimRM(ManagementConnection connection, string computer, PSCr
288299
String.Format("[{0}] Invalid connection credentials", computer),
289300
errorRecord: new ErrorRecord(ex, "BadCredentials", ErrorCategory.AuthenticationError, computer),
290301
target: computer,
291-
isContinue: true,
302+
isContinue: IsSilentContinue,
292303
overrideExceptionMessage: true);
293304
TestFunctionInterrupt();
294305
return true; // break out of protocol loop for this computer
@@ -305,7 +316,7 @@ private bool ProcessCimRM(ManagementConnection connection, string computer, PSCr
305316
errorDetails.Message,
306317
errorRecord: new ErrorRecord(ex, "CimRMError", ErrorCategory.NotSpecified, computer),
307318
target: computer,
308-
isContinue: true,
319+
isContinue: IsSilentContinue,
309320
overrideExceptionMessage: true);
310321
TestFunctionInterrupt();
311322
return true; // break out of protocol loop for this computer
@@ -363,7 +374,7 @@ private bool ProcessCimDCOM(ManagementConnection connection, string computer, PS
363374
String.Format("[{0}] Invalid connection credentials", computer),
364375
errorRecord: new ErrorRecord(ex, "BadCredentials", ErrorCategory.AuthenticationError, computer),
365376
target: computer,
366-
isContinue: true,
377+
isContinue: IsSilentContinue,
367378
overrideExceptionMessage: true);
368379
TestFunctionInterrupt();
369380
return true;
@@ -380,7 +391,7 @@ private bool ProcessCimDCOM(ManagementConnection connection, string computer, PS
380391
errorDetails.Message,
381392
errorRecord: new ErrorRecord(ex, "CimDCOMError", ErrorCategory.NotSpecified, computer),
382393
target: computer,
383-
isContinue: true,
394+
isContinue: IsSilentContinue,
384395
overrideExceptionMessage: true);
385396
TestFunctionInterrupt();
386397
return true;
@@ -467,7 +478,7 @@ private bool ProcessWmi(ManagementConnection connection, string computer, PSCred
467478
String.Format("[{0}] Invalid connection credentials", computer),
468479
errorRecord: new ErrorRecord(ex, "BadCredentials", ErrorCategory.AuthenticationError, computer),
469480
target: computer,
470-
isContinue: true);
481+
isContinue: IsSilentContinue);
471482
TestFunctionInterrupt();
472483
return true;
473484
}
@@ -478,7 +489,7 @@ private bool ProcessWmi(ManagementConnection connection, string computer, PSCred
478489
String.Format("[{0}] Invalid class name ({1}), not found in current namespace ({2})", computer, ClassName, Namespace),
479490
errorRecord: new ErrorRecord(ex, "InvalidClass", ErrorCategory.InvalidType, computer),
480491
target: computer,
481-
isContinue: true);
492+
isContinue: IsSilentContinue);
482493
TestFunctionInterrupt();
483494
return true;
484495
}
@@ -489,7 +500,7 @@ private bool ProcessWmi(ManagementConnection connection, string computer, PSCred
489500
String.Format("[{0}] Failed to access: {1}, in namespace: {2} - There was a provider error. This indicates a potential issue with WMI on the server side.", computer, ClassName, Namespace),
490501
errorRecord: new ErrorRecord(ex, "ProviderLoadFailure", ErrorCategory.NotSpecified, computer),
491502
target: computer,
492-
isContinue: true);
503+
isContinue: IsSilentContinue);
493504
TestFunctionInterrupt();
494505
return true;
495506
}

0 commit comments

Comments
 (0)