Skip to content

Commit efdc500

Browse files
authored
Annotate ThrowTerminatingError with DoesNotReturn attribute (#15352)
1 parent 97ce36a commit efdc500

8 files changed

Lines changed: 9 additions & 0 deletions

File tree

src/Microsoft.Management.Infrastructure.CimCmdlets/CimCommandBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ internal virtual CmdletOperationBase CmdletOperation
672672
/// Throw terminating error
673673
/// </para>
674674
/// </summary>
675+
[System.Diagnostics.CodeAnalysis.DoesNotReturn]
675676
internal void ThrowTerminatingError(Exception exception, string operation)
676677
{
677678
ErrorRecord errorRecord = new(exception, operation, ErrorCategory.InvalidOperation, this);

src/Microsoft.Management.Infrastructure.CimCmdlets/CmdletOperation.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public virtual bool ShouldProcess(string verboseDescription, string verboseWarni
6565
return cmdlet.ShouldProcess(verboseDescription, verboseWarning, caption, out shouldProcessReason);
6666
}
6767

68+
[System.Diagnostics.CodeAnalysis.DoesNotReturn]
6869
public virtual void ThrowTerminatingError(ErrorRecord errorRecord)
6970
{
7071
cmdlet.ThrowTerminatingError(errorRecord);
@@ -115,6 +116,7 @@ public virtual void WriteWarning(string text)
115116
/// Throw terminating error
116117
/// </para>
117118
/// </summary>
119+
[System.Diagnostics.CodeAnalysis.DoesNotReturn]
118120
internal void ThrowTerminatingError(Exception exception, string operation)
119121
{
120122
ErrorRecord errorRecord = new(exception, operation, ErrorCategory.InvalidOperation, this);

src/System.Management.Automation/FormatAndOutput/common/BaseCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ internal TerminatingErrorContext(PSCmdlet command)
2222
_command = command;
2323
}
2424

25+
[System.Diagnostics.CodeAnalysis.DoesNotReturn]
2526
internal void ThrowTerminatingError(ErrorRecord errorRecord)
2627
{
2728
_command.ThrowTerminatingError(errorRecord);

src/System.Management.Automation/engine/DefaultCommandRuntime.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ public PSTransactionContext CurrentPSTransaction
230230
/// if it exists, otherwise throw an invalid operation exception.
231231
/// </summary>
232232
/// <param name="errorRecord">The error record to throw.</param>
233+
[System.Diagnostics.CodeAnalysis.DoesNotReturn]
233234
public void ThrowTerminatingError(ErrorRecord errorRecord)
234235
{
235236
if (errorRecord.Exception != null)

src/System.Management.Automation/engine/ICommandRuntime.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ public interface ICommandRuntime
549549
/// if any information is to be added. It should encapsulate the
550550
/// error record into an exception and then throw that exception.
551551
/// </remarks>
552+
[System.Diagnostics.CodeAnalysis.DoesNotReturn]
552553
void ThrowTerminatingError(ErrorRecord errorRecord);
553554
#endregion ThrowTerminatingError
554555
#endregion misc

src/System.Management.Automation/engine/MshCommandRuntime.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,6 +2055,7 @@ public PSTransactionContext CurrentPSTransaction
20552055
/// <see cref="System.Management.Automation.Cmdlet.ProcessRecord"/>.
20562056
/// etc.
20572057
/// </remarks>
2058+
[System.Diagnostics.CodeAnalysis.DoesNotReturn]
20582059
public void ThrowTerminatingError(ErrorRecord errorRecord)
20592060
{
20602061
ThrowIfStopping();

src/System.Management.Automation/engine/cmdlet.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,7 @@ public PSTransactionContext CurrentPSTransaction
17141714
/// <see cref="System.Management.Automation.Cmdlet.ProcessRecord"/>.
17151715
/// etc.
17161716
/// </remarks>
1717+
[System.Diagnostics.CodeAnalysis.DoesNotReturn]
17171718
public void ThrowTerminatingError(ErrorRecord errorRecord)
17181719
{
17191720
using (PSTransactionManager.GetEngineProtectionScope())

src/System.Management.Automation/namespaces/ProviderBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,7 @@ public virtual string GetResourceString(string baseName, string resourceId)
14171417

14181418
#region ThrowTerminatingError
14191419
/// <Content contentref="System.Management.Automation.Cmdlet.ThrowTerminatingError" />
1420+
[System.Diagnostics.CodeAnalysis.DoesNotReturn]
14201421
public void ThrowTerminatingError(ErrorRecord errorRecord)
14211422
{
14221423
using (PSTransactionManager.GetEngineProtectionScope())

0 commit comments

Comments
 (0)