Пример #1
0
        internal static RuntimeException NewInterpreterExceptionByMessage(
            Type exceptionType,
            Token errToken,
            string message,
            string errorId,
            Exception innerException)
        {
            RuntimeException runtimeException;

            if (exceptionType == typeof(ParseException))
            {
                runtimeException = (RuntimeException) new ParseException(message, errorId, innerException);
            }
            else if (exceptionType == typeof(IncompleteParseException))
            {
                runtimeException = errToken == null || !errToken.EndOfInput() || !string.IsNullOrEmpty(errToken.File) ? (RuntimeException) new ParseException(message, errorId, innerException) : (RuntimeException) new IncompleteParseException(message, errorId, innerException);
            }
            else
            {
                runtimeException = new RuntimeException(message, innerException);
                runtimeException.SetErrorId(errorId);
                runtimeException.SetErrorCategory(ErrorCategory.InvalidOperation);
            }
            if (errToken != null)
            {
                runtimeException.ErrorRecord.SetInvocationInfo(new InvocationInfo((CommandInfo)null, errToken));
            }
            InterpreterError.tracer.TraceException((Exception)runtimeException);
            return(runtimeException);
        }
Пример #2
0
        /// <summary>
        /// Sets the execution scope for the pipeline and then calls the Prepare
        /// abstract method which gets overridden by derived classes.
        /// </summary>
        internal void DoPrepare(IDictionary psDefaultParameterValues)
        {
            CommandProcessorBase oldCurrentCommandProcessor = _context.CurrentCommandProcessor;

            try
            {
                Context.CurrentCommandProcessor = this;
                SetCurrentScopeToExecutionScope();
                Prepare(psDefaultParameterValues);

                // Check obsolete attribute after Prepare so that -WarningAction will be respected for cmdlets
                if (ObsoleteAttribute != null)
                {
                    // Obsolete command is rare. Put the IF here to avoid method call overhead
                    HandleObsoleteCommand(ObsoleteAttribute);
                }
            }
            catch (InvalidComObjectException e)
            {
                // This type of exception could be thrown from parameter binding.
                string msg   = StringUtil.Format(ParserStrings.InvalidComObjectException, e.Message);
                var    newEx = new RuntimeException(msg, e);

                newEx.SetErrorId("InvalidComObjectException");
                throw newEx;
            }
            finally
            {
                Context.CurrentCommandProcessor = oldCurrentCommandProcessor;
                RestorePreviousScope();
            }
        }
Пример #3
0
 internal static RuntimeException NewInterpreterExceptionByMessage(Type exceptionType, IScriptExtent errorPosition, string message, string errorId, Exception innerException)
 {
     RuntimeException exception;
     if (exceptionType == typeof(ParseException))
     {
         exception = new ParseException(message, errorId, innerException);
     }
     else if (exceptionType == typeof(IncompleteParseException))
     {
         exception = new IncompleteParseException(message, errorId, innerException);
     }
     else
     {
         exception = new RuntimeException(message, innerException);
         exception.SetErrorId(errorId);
         exception.SetErrorCategory(ErrorCategory.InvalidOperation);
     }
     if (errorPosition != null)
     {
         exception.ErrorRecord.SetInvocationInfo(new InvocationInfo(null, errorPosition));
     }
     return exception;
 }
Пример #4
0
        internal static RuntimeException NewInterpreterExceptionByMessage(Type exceptionType, IScriptExtent errorPosition, string message, string errorId, Exception innerException)
        {
            RuntimeException exception;

            if (exceptionType == typeof(ParseException))
            {
                exception = new ParseException(message, errorId, innerException);
            }
            else if (exceptionType == typeof(IncompleteParseException))
            {
                exception = new IncompleteParseException(message, errorId, innerException);
            }
            else
            {
                exception = new RuntimeException(message, innerException);
                exception.SetErrorId(errorId);
                exception.SetErrorCategory(ErrorCategory.InvalidOperation);
            }
            if (errorPosition != null)
            {
                exception.ErrorRecord.SetInvocationInfo(new InvocationInfo(null, errorPosition));
            }
            return(exception);
        }
Пример #5
0
 internal static void ThrowExceptionOnError(string errorId, Collection<string> independentErrors, Collection<PSSnapInTypeAndFormatErrors> PSSnapinFilesCollection, RunspaceConfigurationCategory category)
 {
     Collection<string> collection = new Collection<string>();
     if (independentErrors != null)
     {
         foreach (string str in independentErrors)
         {
             collection.Add(str);
         }
     }
     foreach (PSSnapInTypeAndFormatErrors errors in PSSnapinFilesCollection)
     {
         foreach (string str2 in errors.Errors)
         {
             collection.Add(str2);
         }
     }
     if (collection.Count != 0)
     {
         StringBuilder builder = new StringBuilder();
         builder.Append('\n');
         foreach (string str3 in collection)
         {
             builder.Append(str3);
             builder.Append('\n');
         }
         string message = "";
         if (category == RunspaceConfigurationCategory.Types)
         {
             message = StringUtil.Format(ExtendedTypeSystem.TypesXmlError, builder.ToString());
         }
         else if (category == RunspaceConfigurationCategory.Formats)
         {
             message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, builder.ToString());
         }
         RuntimeException exception = new RuntimeException(message);
         exception.SetErrorId(errorId);
         throw exception;
     }
 }
Пример #6
0
 internal static void ThrowExceptionOnError(string errorId, Collection<string> errors, RunspaceConfigurationCategory category)
 {
     if (errors.Count != 0)
     {
         StringBuilder builder = new StringBuilder();
         builder.Append('\n');
         foreach (string str in errors)
         {
             builder.Append(str);
             builder.Append('\n');
         }
         string message = "";
         if (category == RunspaceConfigurationCategory.Types)
         {
             message = StringUtil.Format(ExtendedTypeSystem.TypesXmlError, builder.ToString());
         }
         else if (category == RunspaceConfigurationCategory.Formats)
         {
             message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, builder.ToString());
         }
         RuntimeException exception = new RuntimeException(message);
         exception.SetErrorId(errorId);
         throw exception;
     }
 }