Defines an exception that occurs during compilation of a template.
Inheritance: System.Exception
        /// <summary>
        /// Initialises a new instance of <see cref="TemplateCompilationException"/>.
        /// </summary>
        /// <param name="errors">The set of compiler errors.</param>
        /// <param name="files">The source code that wasn't compiled.</param>
        /// <param name="template">The source template that wasn't compiled.</param>
        public TemplateCompilationException(IEnumerable <RazorEngineCompilerError> errors, CompilationData files, ITemplateSource template)
            : base(TemplateCompilationException.GetMessage(errors, files, template))
        {
            var list = errors.ToList();

            CompilerErrors  = new ReadOnlyCollection <RazorEngineCompilerError>(list);
            CompilationData = files;
            Template        = template.Template;
        }
Example #2
0
 private static StringBuilder BuildRazorParseErrorText(string queryName, TemplateCompilationException ex)
 {
     var message = new StringBuilder();
     foreach (var item in ex.Errors)
     {
         message.AppendLine(String.Format("{0} in {1} at ({2},{3})", item.ErrorText, queryName, item.Line, item.Column));
     }
     return message;
 }
Example #3
0
        /// <summary>
        /// Initialises a new instance of <see cref="TemplateCompilationException"/>.
        /// </summary>
        /// <param name="errors">The set of compiler errors.</param>
        /// <param name="sourceCode">The source code that wasn't compiled.</param>
        /// <param name="template">The source template that wasn't compiled.</param>
        internal TemplateCompilationException(CompilerErrorCollection errors, string sourceCode, string template)
            : base(TemplateCompilationException.GetMessage(errors, sourceCode, template))
        {
            var list = errors.Cast <CompilerError>().ToList();

            Errors     = new ReadOnlyCollection <CompilerError>(list);
            SourceCode = sourceCode;
            Template   = template;
        }
Example #4
0
        public static string GetError(TemplateCompilationException exception)
        {
            var errorStrBuilder = new StringBuilder();
            foreach (var compilerError in exception.CompilerErrors)
            {
                errorStrBuilder.AppendLine();
                errorStrBuilder.AppendFormat("Error Message : {0} {1}", compilerError.ErrorText,compilerError.ErrorNumber);
                errorStrBuilder.AppendLine();
                errorStrBuilder.AppendLine("################");
                errorStrBuilder.AppendFormat("Source Line {0} :{1}\r\n", compilerError.Line - 1, GetLine(exception.SourceCode, compilerError.Line - 1));
                errorStrBuilder.AppendFormat("Error  Line {0} :{1}\r\n", compilerError.Line, GetLine(exception.SourceCode,compilerError.Line));
                errorStrBuilder.AppendFormat("Source Line {0} :{1}\r\n", compilerError.Line + 1, GetLine(exception.SourceCode, compilerError.Line +1));
                errorStrBuilder.AppendLine("################");
            }

            return errorStrBuilder.ToString();
        }
Example #5
0
 static public string GetExceptionMessage(TemplateCompilationException ex)
 {
     string result = "";
     foreach (var error in ex.Errors)
     {
         result += error.ErrorText + "\r\n";
     }
     return result;
 }
        /// <summary>
        /// Displays a custom version of this form to display Razor template compile errors
        /// </summary>
        public static DialogResult ShowTemplateError(TemplateCompilationException E, string TemplateFile)
        {
            using (ExceptionForm F = new ExceptionForm(E, true))
            {
                // Get our relative path from the program root
                string fileRelativePath = TemplateFile.Replace(Program.RootPath, "");

                // Set the window properties
                F.WindowTitle = "Compile Error";
                F.HeaderText = "Template Compile Error";
                F.Message = "An error occured while trying to compile the file \"" + Path.GetFileName(fileRelativePath) + "\"";
                F.ImgIcon = Properties.Resources.vistaWarning;

                if (E.CompilerErrors.Count > 0)
                {
                    StringBuilder builder = new StringBuilder();

                    // Append each error's details into the Details stringbuilder
                    foreach (RazorEngineCompilerError error in E.CompilerErrors)
                    {
                        builder.AppendLine("Compile Error:");
                        builder.AppendLine(error.ErrorText);
                        builder.AppendLine();
                        builder.AppendLine("Error #: " + error.ErrorNumber);
                        builder.AppendLine("File: " + fileRelativePath);
                        builder.AppendLine("Line: " + error.Line);
                        builder.AppendLine("Column: " + error.Column);
                        builder.AppendLine();
                    }

                    // Set the Details pane contents
                    F.ExceptionDetails.Text = builder.ToString();
                }
                else
                {
                    F.ExceptionDetails.Text = E.Message;
                }

                return F.ShowDialog(false);
            }
        }