Ejemplo n.º 1
0
        private void SetErrorVariables(
            Token statementToken,
            RuntimeException rte,
            ExecutionContext context,
            Pipe outputPipe)
        {
            string    str       = (string)null;
            Exception exception = (Exception)rte;

            for (int index = 0; exception != null && index++ < 10; exception = exception.InnerException)
            {
                if (!string.IsNullOrEmpty(exception.StackTrace))
                {
                    str = exception.StackTrace;
                }
            }
            context.SetVariable("global:StackTrace", (object)str);
            if (rte.ErrorRecord.InvocationInfo == null)
            {
                rte.ErrorRecord.SetInvocationInfo(new InvocationInfo((CommandInfo)null, statementToken, context));
            }
            ErrorRecord errorRecord = new ErrorRecord(rte.ErrorRecord, (Exception)rte);

            if (rte is PipelineStoppedException)
            {
                return;
            }
            outputPipe?.UpdateScriptCmdletVariable(ScriptCmdletVariable.Error, (object)errorRecord);
            context.AppendDollarError((object)errorRecord);
        }
Ejemplo n.º 2
0
        internal static void SetErrorVariables(IScriptExtent extent, RuntimeException rte, ExecutionContext context, Pipe outputPipe)
        {
            string    newValue       = null;
            Exception innerException = rte;
            int       num            = 0;

            while ((innerException != null) && (num++ < 10))
            {
                if (!string.IsNullOrEmpty(innerException.StackTrace))
                {
                    newValue = innerException.StackTrace;
                }
                innerException = innerException.InnerException;
            }
            context.SetVariable(SpecialVariables.StackTraceVarPath, newValue);
            InterpreterError.UpdateExceptionErrorRecordPosition(rte, extent);
            ErrorRecord record = rte.ErrorRecord.WrapException(rte);

            if (!(rte is PipelineStoppedException))
            {
                if (outputPipe != null)
                {
                    outputPipe.AppendVariableList(VariableStreamKind.Error, record);
                }
                context.AppendDollarError(record);
            }
        }