internal CmdletProviderInvocationException( ProviderInvocationException innerException, InvocationInfo myInvocation) : base(CmdletProviderInvocationException.GetInnerException((Exception)innerException), myInvocation) { this._providerInvocationException = innerException != null ? innerException : throw new ArgumentNullException(nameof(innerException)); }
internal PipelineStoppedException ManageInvocationException(Exception e) { PipelineStoppedException exception4; try { if (this.Command != null) { ProviderInvocationException innerException = e as ProviderInvocationException; if (innerException != null) { e = new CmdletProviderInvocationException(innerException, this.Command.MyInvocation); } else if (((!(e is PipelineStoppedException) && !(e is CmdletInvocationException)) && (!(e is ActionPreferenceStopException) && !(e is HaltCommandException))) && (!(e is FlowControlException) && !(e is ScriptCallDepthException))) { RuntimeException exception2 = e as RuntimeException; if ((exception2 == null) || !exception2.WasThrownFromThrowStatement) { e = new CmdletInvocationException(e, this.Command.MyInvocation); } } if (this.commandRuntime.UseTransaction != 0) { bool flag = false; for (Exception exception3 = e; exception3 != null; exception3 = exception3.InnerException) { if (exception3 is TimeoutException) { flag = true; break; } } if (flag) { ErrorRecord errorRecord = new ErrorRecord(new InvalidOperationException(TransactionStrings.TransactionTimedOut), "TRANSACTION_TIMEOUT", ErrorCategory.InvalidOperation, e); errorRecord.SetInvocationInfo(this.Command.MyInvocation); e = new CmdletInvocationException(errorRecord); } if (this._context.TransactionManager.HasTransaction && (this._context.TransactionManager.RollbackPreference != RollbackSeverity.Never)) { this.Context.TransactionManager.Rollback(true); } } return((PipelineStoppedException)this.commandRuntime.ManageException(e)); } exception4 = new PipelineStoppedException(); } catch (Exception) { throw; } return(exception4); }
/// <summary> /// Wraps the exception which occurred during cmdlet invocation, /// stores that as the exception to be returned from /// PipelineProcessor.SynchronousExecute, and writes it to /// the error variable. /// </summary> /// <param name="e"> /// The exception to wrap in a CmdletInvocationException or /// CmdletProviderInvocationException. /// </param> /// <returns> /// Always returns PipelineStoppedException. The caller should /// throw this exception. /// </returns> /// <remarks> /// Almost all exceptions which occur during pipeline invocation /// are wrapped in CmdletInvocationException before they are stored /// in the pipeline. However, there are several exceptions: /// /// AccessViolationException, StackOverflowException: /// These are considered to be such severe errors that we /// FailFast the process immediately. /// /// ProviderInvocationException: In this case, we assume that the /// cmdlet is get-item or the like, a thin wrapper around the /// provider API. We discard the original ProviderInvocationException /// and re-wrap its InnerException (the real error) in /// CmdletProviderInvocationException. This makes it easier to reach /// the real error. /// /// CmdletInvocationException, ActionPreferenceStopException: /// This indicates that the cmdlet itself ran a command which failed. /// We could go ahead and wrap the original exception in multiple /// layers of CmdletInvocationException, but this makes it difficult /// for the caller to access the root problem, plus the serialization /// layer might not communicate properties beyond some fixed depth. /// Instead, we choose to not re-wrap the exception. /// /// PipelineStoppedException: This could mean one of two things. /// It usually means that this pipeline has already stopped, /// in which case the pipeline already stores the original error. /// It could also mean that the cmdlet ran a command which was /// stopped by CTRL-C etc, in which case we choose not to /// re-wrap the exception as with CmdletInvocationException. /// </remarks> internal PipelineStoppedException ManageInvocationException(Exception e) { try { if (Command != null) { do // false loop { ProviderInvocationException pie = e as ProviderInvocationException; if (pie != null) { // If a ProviderInvocationException occurred, // discard the ProviderInvocationException and // re-wrap in CmdletProviderInvocationException e = new CmdletProviderInvocationException( pie, Command.MyInvocation); break; } // 1021203-2005/05/09-JonN // HaltCommandException will cause the command // to stop, but not be reported as an error. // 906445-2005/05/16-JonN // FlowControlException should not be wrapped if (e is PipelineStoppedException || e is CmdletInvocationException || e is ActionPreferenceStopException || e is HaltCommandException || e is FlowControlException || e is ScriptCallDepthException) { // do nothing; do not rewrap these exceptions break; } RuntimeException rte = e as RuntimeException; if (rte != null && rte.WasThrownFromThrowStatement) { // do not rewrap a script based throw break; } // wrap all other exceptions e = new CmdletInvocationException( e, Command.MyInvocation); } while (false); // commandRuntime.ManageException will always throw PipelineStoppedException // Otherwise, just return this exception... // If this exception happened in a transacted cmdlet, // rollback the transaction if (commandRuntime.UseTransaction) { // The "transaction timed out" exception is // exceedingly obtuse. We clarify things here. bool isTimeoutException = false; Exception tempException = e; while (tempException != null) { if (tempException is System.TimeoutException) { isTimeoutException = true; break; } tempException = tempException.InnerException; } if (isTimeoutException) { ErrorRecord errorRecord = new ErrorRecord( new InvalidOperationException( TransactionStrings.TransactionTimedOut), "TRANSACTION_TIMEOUT", ErrorCategory.InvalidOperation, e); errorRecord.SetInvocationInfo(Command.MyInvocation); e = new CmdletInvocationException(errorRecord); } // Rollback the transaction in the case of errors. if ( _context.TransactionManager.HasTransaction && _context.TransactionManager.RollbackPreference != RollbackSeverity.Never ) { Context.TransactionManager.Rollback(true); } } return((PipelineStoppedException)this.commandRuntime.ManageException(e)); } // Upstream cmdlets see only that execution stopped // This should only happen if Command is null return(new PipelineStoppedException()); } catch (Exception) { // this method should not throw exceptions; warn about any violations on checked builds and re-throw Diagnostics.Assert(false, "This method should not throw exceptions!"); throw; } }
/// <summary> /// Wraps the exception which occurred during cmdlet invocation, /// stores that as the exception to be returned from /// PipelineProcessor.SynchronousExecute, and writes it to /// the error variable. /// </summary> /// /// <param name="e"> /// The exception to wrap in a CmdletInvocationException or /// CmdletProviderInvocationException. /// </param> /// /// <returns> /// Always returns PipelineStoppedException. The caller should /// throw this exception. /// </returns> /// /// <remarks> /// Almost all exceptions which occur during pipeline invocation /// are wrapped in CmdletInvocationException before they are stored /// in the pipeline. However, there are several exceptions: /// /// AccessViolationException, StackOverflowException: /// These are considered to be such severe errors that we /// FailFast the process immediately. /// /// ProviderInvocationException: In this case, we assume that the /// cmdlet is get-item or the like, a thin wrapper around the /// provider API. We discard the original ProviderInvocationException /// and re-wrap its InnerException (the real error) in /// CmdletProviderInvocationException. This makes it easier to reach /// the real error. /// /// CmdletInvocationException, ActionPreferenceStopException: /// This indicates that the cmdlet itself ran a command which failed. /// We could go ahead and wrap the original exception in multiple /// layers of CmdletInvocationException, but this makes it difficult /// for the caller to access the root problem, plus the serialization /// layer might not communicate properties beyond some fixed depth. /// Instead, we choose to not re-wrap the exception. /// /// PipelineStoppedException: This could mean one of two things. /// It usually means that this pipeline has already stopped, /// in which case the pipeline already stores the original error. /// It could also mean that the cmdlet ran a command which was /// stopped by CTRL-C etc, in which case we choose not to /// re-wrap the exception as with CmdletInvocationException. /// </remarks> internal PipelineStoppedException ManageInvocationException(Exception e) { try { if (null != Command) { do // false loop { ProviderInvocationException pie = e as ProviderInvocationException; if (pie != null) { // If a ProviderInvocationException occurred, // discard the ProviderInvocationException and // re-wrap in CmdletProviderInvocationException e = new CmdletProviderInvocationException( pie, Command.MyInvocation); break; } // 1021203-2005/05/09-JonN // HaltCommandException will cause the command // to stop, but not be reported as an error. // 906445-2005/05/16-JonN // FlowControlException should not be wrapped if (e is PipelineStoppedException || e is CmdletInvocationException || e is ActionPreferenceStopException || e is HaltCommandException || e is FlowControlException || e is ScriptCallDepthException) { // do nothing; do not rewrap these exceptions break; } RuntimeException rte = e as RuntimeException; if (rte != null && rte.WasThrownFromThrowStatement) { // do not rewrap a script based throw break; } // wrap all other exceptions e = new CmdletInvocationException( e, Command.MyInvocation); } while (false); // commandRuntime.ManageException will always throw PipelineStoppedException // Otherwise, just return this exception... // If this exception happened in a transacted cmdlet, // rollback the transaction if (commandRuntime.UseTransaction) { // The "transaction timed out" exception is // exceedingly obtuse. We clarify things here. bool isTimeoutException = false; Exception tempException = e; while (tempException != null) { if (tempException is System.TimeoutException) { isTimeoutException = true; break; } tempException = tempException.InnerException; } if (isTimeoutException) { ErrorRecord errorRecord = new ErrorRecord( new InvalidOperationException( TransactionStrings.TransactionTimedOut), "TRANSACTION_TIMEOUT", ErrorCategory.InvalidOperation, e); errorRecord.SetInvocationInfo(Command.MyInvocation); e = new CmdletInvocationException(errorRecord); } // Rollback the transaction in the case of errors. if ( _context.TransactionManager.HasTransaction && _context.TransactionManager.RollbackPreference != RollbackSeverity.Never ) { Context.TransactionManager.Rollback(true); } } return (PipelineStoppedException)this.commandRuntime.ManageException(e); } // Upstream cmdlets see only that execution stopped // This should only happen if Command is null return new PipelineStoppedException(); } catch (Exception) { // this method should not throw exceptions; warn about any violations on checked builds and re-throw Diagnostics.Assert(false, "This method should not throw exceptions!"); throw; } }
internal PipelineStoppedException ManageInvocationException(Exception e) { PipelineStoppedException exception4; try { if (this.Command != null) { ProviderInvocationException innerException = e as ProviderInvocationException; if (innerException != null) { e = new CmdletProviderInvocationException(innerException, this.Command.MyInvocation); } else if (((!(e is PipelineStoppedException) && !(e is CmdletInvocationException)) && (!(e is ActionPreferenceStopException) && !(e is HaltCommandException))) && (!(e is FlowControlException) && !(e is ScriptCallDepthException))) { RuntimeException exception2 = e as RuntimeException; if ((exception2 == null) || !exception2.WasThrownFromThrowStatement) { e = new CmdletInvocationException(e, this.Command.MyInvocation); } } if (this.commandRuntime.UseTransaction != 0) { bool flag = false; for (Exception exception3 = e; exception3 != null; exception3 = exception3.InnerException) { if (exception3 is TimeoutException) { flag = true; break; } } if (flag) { ErrorRecord errorRecord = new ErrorRecord(new InvalidOperationException(TransactionStrings.TransactionTimedOut), "TRANSACTION_TIMEOUT", ErrorCategory.InvalidOperation, e); errorRecord.SetInvocationInfo(this.Command.MyInvocation); e = new CmdletInvocationException(errorRecord); } if (this._context.TransactionManager.HasTransaction && (this._context.TransactionManager.RollbackPreference != RollbackSeverity.Never)) { this.Context.TransactionManager.Rollback(true); } } return (PipelineStoppedException) this.commandRuntime.ManageException(e); } exception4 = new PipelineStoppedException(); } catch (Exception) { throw; } return exception4; }
private void DisposeCommands() { this.stopping = true; this.FlushLog(); if (this._commands != null) { for (int i = 0; i < this._commands.Count; i++) { CommandProcessorBase base2 = this._commands[i]; if (base2 != null) { try { base2.CommandRuntime.RemoveVariableListsInPipe(); base2.Dispose(); } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); InvocationInfo myInvocation = null; if (base2.Command != null) { myInvocation = base2.Command.MyInvocation; } ProviderInvocationException innerException = exception as ProviderInvocationException; if (innerException != null) { exception = new CmdletProviderInvocationException(innerException, myInvocation); } else { exception = new CmdletInvocationException(exception, myInvocation); MshLog.LogCommandHealthEvent(base2.Command.Context, exception, Severity.Warning); } this.RecordFailure(exception, base2.Command); } } } } this._commands = null; if (this._redirectionPipes != null) { foreach (PipelineProcessor processor in this._redirectionPipes) { try { if (processor != null) { processor.Dispose(); } } catch (Exception exception3) { CommandProcessorBase.CheckForSevereException(exception3); } } } this._redirectionPipes = null; }