internal bool RecordFailure(Exception e, InternalCommand command) { bool stopping = false; lock (this.StopReasonLock) { if (this.firstTerminatingError == null) { RuntimeException.LockStackTrace(e); this.firstTerminatingError = e; } else if ((!(this.firstTerminatingError is PipelineStoppedException) && (command != null)) && (command.Context != null)) { Exception innerException = e; while (((innerException is TargetInvocationException) || (innerException is CmdletInvocationException)) && (innerException.InnerException != null)) { innerException = innerException.InnerException; } if (!(innerException is PipelineStoppedException)) { InvalidOperationException exception = new InvalidOperationException(StringUtil.Format(PipelineStrings.SecondFailure, new object[] { this.firstTerminatingError.GetType().Name, this.firstTerminatingError.StackTrace, innerException.GetType().Name, innerException.StackTrace }), innerException); MshLog.LogCommandHealthEvent(command.Context, exception, Severity.Warning); } } stopping = this.stopping; this.stopping = true; } return(!stopping); }
// Keep in sync: // S.M.A.CommandProcessorBase.CheckForSevereException // S.M.A.Internal.ConsoleHost.CheckForSevereException // S.M.A.Commands.CommandsCommon.CheckForSevereException // S.M.A.Commands.UtilityCommon.CheckForSevereException /// <summary> /// Checks whether the exception is a severe exception which should /// cause immediate process failure. /// </summary> /// <param name="cmdlet"></param> /// <param name="e"></param> /// <remarks> /// CB says 02/23/2005: I personally would err on the side /// of treating OOM like an application exception, rather than /// a critical system failure.I think this will be easier to justify /// in Orcas, if we tease apart the two cases of OOM better. /// But even in Whidbey, how likely is it that we couldnt JIT /// some backout code? At that point, the process or possibly /// the machine is likely to stop executing soon no matter /// what you do in this routine. So I would just consider /// AccessViolationException. (I understand why you have SO here, /// at least temporarily). /// </remarks> internal static void CheckForSevereException(Cmdlet cmdlet, Exception e) { if (e is AccessViolationException || e is StackOverflowException) { try { if (!alreadyFailing) { alreadyFailing = true; // Log a command health event for this critical error. MshLog.LogCommandHealthEvent( cmdlet.Context, e, Severity.Critical); } } finally { if (!designForTestability_SkipFailFast) { WindowsErrorReporting.FailFast(e); } } } }
// Keep in sync: // S.M.A.CommandProcessorBase.CheckForSevereException // S.M.A.Internal.ConsoleHost.CheckForSevereException // S.M.A.Commands.CommandsCommon.CheckForSevereException // S.M.A.Commands.UtilityCommon.CheckForSevereException /// <summary> /// Checks whether the exception is a severe exception which should /// cause immediate process failure. /// </summary> /// <param name="cmdlet">can be null</param> /// <param name="e"></param> /// <remarks> /// CB says 02/23/2005: I personally would err on the side /// of treating OOM like an application exception, rather than /// a critical system failure.I think this will be easier to justify /// in Orcas, if we tease apart the two cases of OOM better. /// But even in Whidbey, how likely is it that we couldnt JIT /// some backout code? At that point, the process or possibly /// the machine is likely to stop executing soon no matter /// what you do in this routine. So I would just consider /// AccessViolationException. (I understand why you have SO here, /// at least temporarily). /// </remarks> internal static void CheckForSevereException(PSCmdlet cmdlet, Exception e) { if (e is AccessViolationException || e is StackOverflowException) { try { if (!alreadyFailing) { alreadyFailing = true; // Get the ExecutionContext from the thread. ExecutionContext context = (null != cmdlet) ? cmdlet.Context : LocalPipeline.GetExecutionContextFromTLS(); // Log a command health event for this critical error. MshLog.LogCommandHealthEvent(context, e, Severity.Critical); } } finally { if (!designForTestability_SkipFailFast) { WindowsErrorReporting.FailFast(e); } } } }
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; }
internal static void CheckForSevereException(Cmdlet cmdlet, Exception e) { if (e as AccessViolationException != null || e as StackOverflowException != null) { try { if (!CommandsCommon.alreadyFailing) { CommandsCommon.alreadyFailing = true; MshLog.LogCommandHealthEvent(cmdlet.Context, e, Severity.Critical); } } finally { if (!CommandsCommon.designForTestability_SkipFailFast) { WindowsErrorReporting.FailFast(e); } } } }
internal static void CheckForSevereException(PSCmdlet cmdlet, Exception e) { if ((e is AccessViolationException) || (e is StackOverflowException)) { try { if (!alreadyFailing) { alreadyFailing = true; ExecutionContext executionContext = (cmdlet != null) ? cmdlet.Context : LocalPipeline.GetExecutionContextFromTLS(); MshLog.LogCommandHealthEvent(executionContext, e, Severity.Critical); } } finally { if (!designForTestability_SkipFailFast) { WindowsErrorReporting.FailFast(e); } } } }