public virtual void MappingSyntaxErrorDuringCompilationOfFileIsCorrect() { // Arrange string inputFilePath = Path.Combine(_filesDirectoryPath, string.Format("invalid-syntax/{0}/style{1}", _subfolderName, _fileExtension)); SassСompilationException exception = null; // Act try { CompilationResult result = SassCompiler.CompileFile(inputFilePath); } catch (SassСompilationException e) { exception = e; } // Assert Assert.NotNull(exception); Assert.NotEmpty(exception.Message); Assert.Equal(GetCanonicalPath(inputFilePath), exception.File); Assert.Equal(3, exception.LineNumber); Assert.Equal(13, exception.ColumnNumber); }
/// <summary> /// Generates a detailed error message /// </summary> /// <param name="sassСompilationException">Sass compilation exception</param> /// <returns>Detailed error message</returns> public static string Format(SassСompilationException sassСompilationException) { string message = sassСompilationException.Text; string filePath = sassСompilationException.File; int lineNumber = sassСompilationException.LineNumber; int columnNumber = sassСompilationException.ColumnNumber; string sourceCode = sassСompilationException.Source; string sourceFragment = SourceCodeNavigator.GetSourceFragment(sourceCode, new SourceCodeNodeCoordinates(lineNumber, columnNumber)); var errorMessage = new StringBuilder(); errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_Message, message); if (!string.IsNullOrWhiteSpace(filePath)) { errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_File, filePath); } if (lineNumber > 0) { errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_LineNumber, lineNumber.ToString(CultureInfo.InvariantCulture)); } if (columnNumber > 0) { errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_ColumnNumber, columnNumber.ToString(CultureInfo.InvariantCulture)); } if (!string.IsNullOrWhiteSpace(sourceFragment)) { errorMessage.AppendFormatLine("{1}:{0}{0}{2}", Environment.NewLine, Strings.ErrorDetails_SourceFragment, sourceFragment); } return errorMessage.ToString(); }
public virtual void MappingFileNotFoundErrorDuringCompilationOfCodeIsCorrect() { // Arrange string inputFilePath = Path.Combine(_filesDirectoryPath, string.Format("non-existing-files/{0}/base{1}", _subfolderName, _fileExtension)); string inputCode = File.ReadAllText(inputFilePath); var options = new CompilationOptions { SourceMap = true }; SassСompilationException exception = null; // Act try { CompilationResult result = SassCompiler.Compile(inputCode, inputFilePath, options: options); } catch (SassСompilationException e) { exception = e; } // Assert Assert.NotNull(exception); Assert.NotEmpty(exception.Message); Assert.Equal(GetCanonicalPath(inputFilePath), exception.File); Assert.Equal(_syntaxType == SyntaxType.Sass ? 5 : 6, exception.LineNumber); Assert.Equal(1, exception.ColumnNumber); }
private static void WriteError(string title, SassСompilationException exception) { Console.WriteLine("{0} See details:", title); Console.WriteLine(); Console.WriteLine(SassErrorHelpers.Format(exception)); Console.WriteLine(); }
/// <summary> /// Writes a detailed error message to the buffer /// </summary> /// <param name="buffer">Instance of <see cref="StringBuilder"/></param> /// <param name="sassСompilationException">Sass compilation exception</param> private static void WriteCompilationErrorDetails(StringBuilder buffer, SassСompilationException sassСompilationException) { if (sassСompilationException.ErrorCode > 0) { buffer.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_ErrorCode, sassСompilationException.ErrorCode); } buffer.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_Description, sassСompilationException.Description); if (!string.IsNullOrWhiteSpace(sassСompilationException.File)) { buffer.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_File, sassСompilationException.File); } if (sassСompilationException.LineNumber > 0) { buffer.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_LineNumber, sassСompilationException.LineNumber.ToString(CultureInfo.InvariantCulture)); } if (sassСompilationException.ColumnNumber > 0) { buffer.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_ColumnNumber, sassСompilationException.ColumnNumber.ToString(CultureInfo.InvariantCulture)); } if (!string.IsNullOrWhiteSpace(sassСompilationException.SourceFragment)) { buffer.AppendFormatLine("{1}:{0}{0}{2}", Environment.NewLine, Strings.ErrorDetails_SourceFragment, sassСompilationException.SourceFragment); } }
/// <summary> /// Generates a detailed error message /// </summary> /// <param name="sassСompilationException">Sass compilation exception</param> /// <param name="omitMessage">Flag for whether to omit message</param> /// <returns>Detailed error message</returns> public static string GenerateErrorDetails(SassСompilationException sassСompilationException, bool omitMessage = false) { if (sassСompilationException == null) { throw new ArgumentNullException(nameof(sassСompilationException)); } var stringBuilderPool = StringBuilderPool.Shared; StringBuilder detailsBuilder = stringBuilderPool.Rent(); WriteCommonErrorDetails(detailsBuilder, sassСompilationException, omitMessage); WriteCompilationErrorDetails(detailsBuilder, sassСompilationException); detailsBuilder.TrimEnd(); string errorDetails = detailsBuilder.ToString(); stringBuilderPool.Return(detailsBuilder); return(errorDetails); }
/// <summary> /// Generates a detailed error message /// </summary> /// <param name="sassСompilationException">Sass compilation exception</param> /// <returns>Detailed error message</returns> public static string Format(SassСompilationException sassСompilationException) { string message = sassСompilationException.Text; string filePath = sassСompilationException.File; int lineNumber = sassСompilationException.LineNumber; int columnNumber = sassСompilationException.ColumnNumber; string sourceCode = sassСompilationException.Source; string sourceFragment = SourceCodeNavigator.GetSourceFragment(sourceCode, new SourceCodeNodeCoordinates(lineNumber, columnNumber)); var errorMessage = new StringBuilder(); errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_Message, message); if (!string.IsNullOrWhiteSpace(filePath)) { errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_File, filePath); } if (lineNumber > 0) { errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_LineNumber, lineNumber.ToString(CultureInfo.InvariantCulture)); } if (columnNumber > 0) { errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_ColumnNumber, columnNumber.ToString(CultureInfo.InvariantCulture)); } if (!string.IsNullOrWhiteSpace(sourceFragment)) { errorMessage.AppendFormatLine("{1}:{0}{0}{2}", Environment.NewLine, Strings.ErrorDetails_SourceFragment, sourceFragment); } return(errorMessage.ToString()); }
public static string Format(SassСompilationException sassСompilationException) { return(GenerateErrorDetails(sassСompilationException)); }