/// <summary>
        /// Conversion between an error internal representation and ErrorRecord
        /// </summary>
        /// <param name="error">internal error object</param>
        /// <returns>corresponding ErrorRecord instance</returns>
        private static ErrorRecord GenerateErrorRecord(FormattingError error)
        {
            ErrorRecord errorRecord = null;
            string      msg         = null;
            PSPropertyExpressionError psPropertyExpressionError = error as PSPropertyExpressionError;

            if (psPropertyExpressionError != null)
            {
                errorRecord = new ErrorRecord(
                    psPropertyExpressionError.result.Exception,
                    "PSPropertyExpressionError",
                    ErrorCategory.InvalidArgument,
                    psPropertyExpressionError.sourceObject);

                msg = StringUtil.Format(FormatAndOut_format_xxx.PSPropertyExpressionError,
                                        psPropertyExpressionError.result.ResolvedExpression.ToString());
                errorRecord.ErrorDetails = new ErrorDetails(msg);
            }

            StringFormatError formattingError = error as StringFormatError;

            if (formattingError != null)
            {
                errorRecord = new ErrorRecord(
                    formattingError.exception,
                    "formattingError",
                    ErrorCategory.InvalidArgument,
                    formattingError.sourceObject);

                msg = StringUtil.Format(FormatAndOut_format_xxx.FormattingError,
                                        formattingError.formatString);
                errorRecord.ErrorDetails = new ErrorDetails(msg);
            }
            return(errorRecord);
        }
Example #2
0
        /// <summary>
        /// log a failed evaluation of an PSPropertyExpression.
        /// </summary>
        /// <param name="result">PSPropertyExpressionResult containing the failed evaluation data.</param>
        /// <param name="sourceObject">Object used to evaluate the PSPropertyExpression.</param>
        internal void LogPSPropertyExpressionFailedResult(PSPropertyExpressionResult result, object sourceObject)
        {
            if (!_formatErrorPolicy.ShowErrorsAsMessages)
            {
                return;
            }
            PSPropertyExpressionError error = new PSPropertyExpressionError();

            error.result       = result;
            error.sourceObject = sourceObject;
            _formattingErrorList.Add(error);
        }