Beispiel #1
0
        internal void HandleError(JSError errorId, bool forceToError = false)
        {
            if ((errorId != JSError.UndeclaredVariable && errorId != JSError.UndeclaredFunction) || !Document.HasAlreadySeenErrorFor(Code))
            {
                var severity     = GetSeverity(errorId);
                var errorMessage = GetErrorString(errorId);
                var context      = this.ErrorSegment;
                if (!context.IsNullOrWhiteSpace())
                {
                    errorMessage += CommonStrings.ContextSeparator + context;
                }

                var error = new UglifyError()
                {
                    IsError     = forceToError || severity < 2,
                    File        = Document.FileContext,
                    Severity    = severity,
                    Subcategory = UglifyError.GetSubcategory(severity),
                    ErrorNumber = (int)errorId,
                    ErrorCode   = "JS{0}".FormatInvariant((int)errorId),
                    StartLine   = this.StartLineNumber,
                    StartColumn = this.StartColumn + 1,
                    EndLine     = this.EndLineNumber,
                    EndColumn   = this.EndColumn + 1,
                    Message     = errorMessage,
                };

                Document.HandleError(error);
            }
        }
Beispiel #2
0
        //---------------------------------------------------------------------------------------
        // HandleError
        //
        //  Handle an error. There are two actions that can be taken when an error occurs:
        //    - throwing an exception with no recovering action (eval case)
        //    - notify the host that an error occurred and let the host decide whether or not
        //      parsing has to continue (the host returns true when parsing has to continue)
        //---------------------------------------------------------------------------------------

        internal void HandleError(UglifyError error)
        {
            if (Parser != null)
            {
                Parser.OnCompilerError(error);
            }
        }
        /// <summary>
        /// Generates a detailed error message based on object UglifyError
        /// </summary>
        /// <param name="error">Object UglifyError</param>
        /// <returns>Detailed error message</returns>
        internal static string FormatContextError(UglifyError error)
        {
            var           stringBuilderPool   = StringBuilderPool.Shared;
            StringBuilder errorMessageBuilder = stringBuilderPool.Rent();

            errorMessageBuilder.AppendFormatLine("{0}: {1}", CoreStrings.ErrorDetails_Message, error.Message);
            errorMessageBuilder.AppendFormatLine("{0}: {1}", CoreStrings.ErrorDetails_ErrorCode, error.ErrorCode);
            errorMessageBuilder.AppendFormatLine("{0}: {1}", CoreStrings.ErrorDetails_Severity, error.Severity);
            errorMessageBuilder.AppendFormatLine("{0}: {1}", CoreStrings.ErrorDetails_Subcategory, error.Subcategory);
            if (!string.IsNullOrWhiteSpace(error.HelpKeyword))
            {
                errorMessageBuilder.AppendFormatLine("{0}: {1}", CoreStrings.ErrorDetails_HelpKeyword, error.HelpKeyword);
            }
            if (!string.IsNullOrWhiteSpace(error.File))
            {
                errorMessageBuilder.AppendFormatLine("{0}: {1}", CoreStrings.ErrorDetails_File, error.File);
            }
            errorMessageBuilder.AppendFormatLine("{0}: {1}", CoreStrings.ErrorDetails_StartLine, error.StartLine);
            errorMessageBuilder.AppendFormatLine("{0}: {1}", CoreStrings.ErrorDetails_StartColumn, error.StartColumn);
            errorMessageBuilder.AppendFormatLine("{0}: {1}", CoreStrings.ErrorDetails_EndLine, error.EndLine);
            errorMessageBuilder.AppendFormat("{0}: {1}", CoreStrings.ErrorDetails_EndColumn, error.EndColumn);

            string errorMessage = errorMessageBuilder.ToString();

            stringBuilderPool.Return(errorMessageBuilder);

            return(errorMessage);
        }
Beispiel #4
0
 private void WriteError(string file, UglifyError error)
 {
     _errorMessages.AppendLine("JavaScript compilation failed");
     _errorMessages.AppendLine("\tError code: " + error.ErrorNumber);
     _errorMessages.AppendLine("\t" + error.Message);
     _errorMessages.AppendLine("\t" + file + "(" + error.StartLine + ":" + error.EndLine + ", " + error.StartColumn + ":" + error.EndColumn + ")");
     _errorMessages.AppendLine();
 }
Beispiel #5
0
        /// <summary>
        /// CSS parser error handler
        /// </summary>
        /// <param name="source">The source of the event</param>
        /// <param name="args">A NUglify.ContextErrorEventArgs
        /// that contains the event data</param>
        private void ParserErrorHandler(object source, ContextErrorEventArgs args)
        {
            UglifyError error = args.Error;

            if (error.Severity <= Severity)
            {
                throw new NUglifyParsingException(FormatContextError(error));
            }
        }
        /// <summary>
        /// Parse error handler
        /// </summary>
        /// <param name="source">The source of the event</param>
        /// <param name="args">A <see cref="ContextErrorEventArgs"/> that contains the event data</param>
        public void ParseErrorHandler(object source, ContextErrorEventArgs args)
        {
            UglifyError error = args.Error;

            if (error.Severity <= _warningLevel)
            {
                var errorDetails = new MinificationErrorInfo(error.Message, error.StartLine, error.StartColumn,
                                                             string.Empty);
                if (error.Severity < 1)
                {
                    _errors.Add(errorDetails);
                }
                else
                {
                    _warnings.Add(errorDetails);
                }
            }
        }