Example #1
0
        internal ProviderInvocationException(string errorId, string resourceStr, System.Management.Automation.ProviderInfo provider, string path, Exception innerException, bool useInnerExceptionMessage) : base(RetrieveMessage(errorId, resourceStr, provider, path, innerException), innerException)
        {
            this._providerInfo = provider;
            this._message      = base.Message;
            Exception replaceParentContainsErrorRecordException = null;

            if (useInnerExceptionMessage)
            {
                replaceParentContainsErrorRecordException = innerException;
            }
            else
            {
                replaceParentContainsErrorRecordException = new ParentContainsErrorRecordException(this);
            }
            IContainsErrorRecord record = innerException as IContainsErrorRecord;

            if ((record != null) && (record.ErrorRecord != null))
            {
                this._errorRecord = new System.Management.Automation.ErrorRecord(record.ErrorRecord, replaceParentContainsErrorRecordException);
            }
            else
            {
                this._errorRecord = new System.Management.Automation.ErrorRecord(replaceParentContainsErrorRecordException, errorId, ErrorCategory.InvalidOperation, null);
            }
        }
Example #2
0
        private static void ThrowIfVariableIsPrivate(PSVariable variable)
        {
            if (variable.Visibility != SessionStateEntryVisibility.Private)
            {
                return;
            }

            var exception = new SessionStateException(
                String.Format("Cannot access the variable '${0}' because it is a private variable", variable.Name),
                variable.ItemName,
                SessionStateCategory.Variable);

            string errorId         = "VariableIsPrivate";
            var    parentException = new ParentContainsErrorRecordException(exception);
            var    error           = new ErrorRecord(parentException, errorId, ErrorCategory.PermissionDenied, variable.Name);

            exception.ErrorRecord = error;

            throw exception;
        }
        /// <summary>
        /// Constructor to make it easy to wrap a provider exception.
        /// </summary>
        /// <param name="errorId">
        /// This string will be used to construct the FullyQualifiedErrorId,
        /// which is a global identifier of the error condition.  Pass a
        /// non-empty string which is specific to this error condition in
        /// this context.
        /// </param>
        /// <param name="resourceStr">
        /// This is the message template string
        /// </param>
        /// <param name="provider">
        /// The provider information used to format into the message.
        /// </param>
        /// <param name="path">
        /// The path that was being processed when the exception occurred.
        /// </param>
        /// <param name="innerException">
        /// The exception that was thrown by the provider.
        /// </param>
        /// <param name="useInnerExceptionMessage">
        /// If true, the message from the inner exception will be used if the exception contains
        /// an ErrorRecord. If false, the error message retrieved using the errorId will be used.
        /// </param>
        internal ProviderInvocationException(
            string errorId,
            string resourceStr,
            ProviderInfo provider,
            string path,
            Exception innerException,
            bool useInnerExceptionMessage)
            : base(
                RetrieveMessage(errorId, resourceStr, provider, path, innerException),
                innerException)
        {
            _providerInfo = provider;

            _message = base.Message;

            Exception errorRecordException = null;

            if (useInnerExceptionMessage)
            {
                errorRecordException = innerException;
            }
            else
            {
                errorRecordException = new ParentContainsErrorRecordException(this);
            }

            IContainsErrorRecord icer = innerException as IContainsErrorRecord;

            if (icer != null && icer.ErrorRecord != null)
            {
                _errorRecord = new ErrorRecord(icer.ErrorRecord, errorRecordException);
            }
            else
            {
                _errorRecord = new ErrorRecord(
                    errorRecordException,
                    errorId,
                    ErrorCategory.InvalidOperation,
                    null);
            }
        }
Example #4
0
        internal static WildcardPatternException NewWildcardPatternException(string invalidPattern)
        {
            string message =
                StringUtil.Format(WildcardPatternStrings.InvalidPattern,
                                  invalidPattern
                                  );

            ParentContainsErrorRecordException pce =
                new ParentContainsErrorRecordException(message);

            ErrorRecord er =
                new ErrorRecord(pce,
                                "WildcardPattern_Invalid",
                                ErrorCategory.InvalidArgument,
                                null);

            WildcardPatternException e =
                new WildcardPatternException(er);

            return(e);
        }
 internal ProviderInvocationException(string errorId, string resourceStr, System.Management.Automation.ProviderInfo provider, string path, Exception innerException, bool useInnerExceptionMessage) : base(RetrieveMessage(errorId, resourceStr, provider, path, innerException), innerException)
 {
     this._providerInfo = provider;
     this._message = base.Message;
     Exception replaceParentContainsErrorRecordException = null;
     if (useInnerExceptionMessage)
     {
         replaceParentContainsErrorRecordException = innerException;
     }
     else
     {
         replaceParentContainsErrorRecordException = new ParentContainsErrorRecordException(this);
     }
     IContainsErrorRecord record = innerException as IContainsErrorRecord;
     if ((record != null) && (record.ErrorRecord != null))
     {
         this._errorRecord = new System.Management.Automation.ErrorRecord(record.ErrorRecord, replaceParentContainsErrorRecordException);
     }
     else
     {
         this._errorRecord = new System.Management.Automation.ErrorRecord(replaceParentContainsErrorRecordException, errorId, ErrorCategory.InvalidOperation, null);
     }
 }
Example #6
0
        /// <summary>
        /// Constructor to make it easy to wrap a provider exception
        /// </summary>
        /// 
        /// <param name="errorId">
        /// This string will be used to construct the FullyQualifiedErrorId,
        /// which is a global identifier of the error condition.  Pass a
        /// non-empty string which is specific to this error condition in
        /// this context.
        /// </param>
        /// 
        /// <param name="resourceStr">
        /// This is the message template string
        /// </param>
        /// 
        /// <param name="provider">
        /// The provider information used to format into the message.
        /// </param>
        /// 
        /// <param name="path">
        /// The path that was being processed when the exception occurred.
        /// </param>
        /// 
        /// <param name="innerException">
        /// The exception that was thrown by the provider.
        /// </param>
        /// 
        /// <param name="useInnerExceptionMessage">
        /// If true, the message from the inner exception will be used if the exception contains
        /// an ErrorRecord. If false, the error message retrieved using the errorId will be used.
        /// </param>
        /// 
        internal ProviderInvocationException(
            string errorId,
            string resourceStr,
            ProviderInfo provider,
            string path,
            Exception innerException,
            bool useInnerExceptionMessage)
            : base(
                RetrieveMessage(errorId, resourceStr, provider, path, innerException),
                innerException)
        {
            _providerInfo = provider;

            _message = base.Message;

            Exception errorRecordException = null;
            if (useInnerExceptionMessage)
            {
                errorRecordException = innerException;
            }
            else
            {
                errorRecordException = new ParentContainsErrorRecordException(this);
            }

            IContainsErrorRecord icer = innerException as IContainsErrorRecord;
            if (null != icer && null != icer.ErrorRecord)
            {
                _errorRecord = new ErrorRecord(icer.ErrorRecord, errorRecordException);
            }
            else
            {
                _errorRecord = new ErrorRecord(
                    errorRecordException,
                    errorId,
                    ErrorCategory.InvalidOperation,
                    null);
            }
        }
Example #7
0
        internal static WildcardPatternException NewWildcardPatternException(string invalidPattern)
        {
            string message =
                StringUtil.Format(WildcardPatternStrings.InvalidPattern,
                    invalidPattern
                );

            ParentContainsErrorRecordException pce =
                new ParentContainsErrorRecordException(message);

            ErrorRecord er =
                new ErrorRecord(pce,
                                 "WildcardPattern_Invalid",
                                 ErrorCategory.InvalidArgument,
                                 null);

            WildcardPatternException e =
                new WildcardPatternException(er);

            return e;
        }
Example #8
0
 internal static WildcardPatternException NewWildcardPatternException(string invalidPattern)
 {
     ParentContainsErrorRecordException exception = new ParentContainsErrorRecordException(StringUtil.Format(WildcardPatternStrings.InvalidPattern, invalidPattern));
     return new WildcardPatternException(new ErrorRecord(exception, "WildcardPattern_Invalid", ErrorCategory.InvalidArgument, null));
 }
Example #9
0
        internal static WildcardPatternException NewWildcardPatternException(string invalidPattern)
        {
            ParentContainsErrorRecordException exception = new ParentContainsErrorRecordException(StringUtil.Format(WildcardPatternStrings.InvalidPattern, invalidPattern));

            return(new WildcardPatternException(new ErrorRecord(exception, "WildcardPattern_Invalid", ErrorCategory.InvalidArgument, null)));
        }