Apply a single, predictable error-handling strategy across cmdlets and SDK wrappers:
throwIfNotExists (or callers rely on it), every related “read/modify” path must honor it the same way (return null vs throw), and callers should not silently diverge between Get/With* operations.AzPSArgumentException (not generic InvalidOperationException), with clear text (including the expected format when relevant).-ResourceId, validate format upfront and add scenario tests for both success and failure.-Force is not set, warn and stop/confirm; if -Force is set, proceed.Example pattern (existence + intent + -Force + consistent throw semantics):
PSDeploymentStackWhatIfResult existing = null;
try
{
existing = sdk.GetResourceGroupDeploymentStackWhatIfResult(
rgName, stackName, throwIfNotExists: false);
}
catch (Exception ex)
{
// Only treat as non-fatal if the strategy explicitly allows graceful degradation.
existing = null;
}
if (existing != null)
{
// NEW cmdlet intent: warn when exists; Set cmdlet would invert this logic.
if (!Force.IsPresent)
throw new AzPSArgumentException($"What-If result '{stackName}' already exists. Use -Force to overwrite.");
}
else
{
// SET cmdlet intent: warn when missing; NEW cmdlet proceeds.
if (this.IsSetCmdlet && !Force.IsPresent)
throw new AzPSArgumentException($"What-If result '{stackName}' not found. Use -Force to continue.");
}
This standard improves graceful degradation, error clarity, and reduces inconsistent behavior across cmdlets and SDK conversion layers.