/// <summary> /// Try to match a function name by reading RawError.Input. /// If a match is found, the method outputs the result into /// RawError.Function and returns true. /// </summary> /// <param name="parser">An instance of parser, this parameter /// cannot be null.</param> /// <param name="args">An instance of RawError. This parameter /// cannot be null.</param> /// <returns>True if a match occurs, false otherwise.</returns> public bool TryParse(StackTraceParser parser, RawError args) { int posEndingParenthesis; int posOpeningParenthesis; int posName; string res; int i; UiExceptionHelper.CheckNotNull(parser, "parser"); UiExceptionHelper.CheckNotNull(args, "args"); posEndingParenthesis = args.Input.LastIndexOf(")"); posOpeningParenthesis = args.Input.LastIndexOf("("); if (posEndingParenthesis == -1 || posOpeningParenthesis == -1 || posOpeningParenthesis > posEndingParenthesis) return (false); posName = -1; for (i = posOpeningParenthesis - 1; i >= 0; i--) { if (args.Input[i] == ' ') break; posName = i; } if (posName == -1) return (false); res = args.Input.Substring(posName, posEndingParenthesis - posName + 1); args.Function = res; return (true); }
/// <summary> /// Locates and fills RawError.Path property with the first /// Windows path values found from RawError.Input property. /// </summary> /// <param name="parser">The stack trace parser. This parameter /// must not be null.</param> /// <param name="args">The RawError from which retrieving and /// filling Input and Path properties. This parameter cannot not /// be null.</param> /// <returns>True if a match occured, false otherwise.</returns> public bool TryParse(StackTraceParser parser, RawError args) { int posDriveLetter; int posTrailingColon; string path; UiExceptionHelper.CheckNotNull(parser, "parser"); UiExceptionHelper.CheckNotNull(args, "args"); posDriveLetter = lookForDriveLetter(args.Input, 0); if (posDriveLetter == -1) return (false); posTrailingColon = PathCompositeParser.IndexOfTrailingColon(args.Input, posDriveLetter + 3); if (posTrailingColon == -1) return (false); path = args.Input.Substring(posDriveLetter, posTrailingColon - posDriveLetter); path = path.Trim(); if (path.Length <= 3) return (false); args.Path = path; return (true); }
/// <summary> /// Locates and fills RawError.Path property with the first /// Unix path values found from RawError.Input property. /// </summary> /// <param name="parser">The stack trace parser. This parameter /// must not be null.</param> /// <param name="args">The RawError from which retrieving and /// filling Input and Path properties. This parameter cannot not /// be null.</param> /// <returns>True if a match occured, false otherwise.</returns> public bool TryParse(StackTraceParser parser, RawError args) { int posSlash; int posColon; string path; UiExceptionHelper.CheckNotNull(parser, "parser"); UiExceptionHelper.CheckNotNull(args, "args"); if ((posSlash = indexOfFirstSlash(args.Input, 0)) == -1) return (false); if ((posColon = PathCompositeParser.IndexOfTrailingColon(args.Input, posSlash + 1)) == -1) return (false); path = args.Input.Substring(posSlash, posColon - posSlash); path = path.Trim(); if (path.Length <= 1) return (false); args.Path = path; return (true); }
/// <summary> /// Try to read from a stack trace line a path value given either /// under the form of a Windows path or a UNIX path. If a match occurs /// the method fills args.Function with the identified data. /// </summary> /// <param name="parser">The instance of StackTraceParser, this parameter /// cannot be null.</param> /// <param name="args">The instance of RawError from where read and write /// RawError.Input and RawError.Function properties. This parameter /// cannot be null.</param> /// <returns>True if a match occurs, false otherwise.</returns> public bool TryParse(StackTraceParser parser, RawError args) { foreach (IErrorParser item in _array) if (item.TryParse(parser, args)) return (true); return (false); }
/// <summary> /// Try to match a function name by reading RawError.Input. /// If a match is found, the method outputs the result into /// RawError.Function and returns true. /// </summary> /// <param name="parser">An instance of parser, this parameter /// cannot be null.</param> /// <param name="args">An instance of RawError. This parameter /// cannot be null.</param> /// <returns>True if a match occurs, false otherwise.</returns> public bool TryParse(StackTraceParser parser, RawError args) { int posEndingParenthesis; int posOpeningParenthesis; int posName; int endName; string res; int i; UiExceptionHelper.CheckNotNull(parser, "parser"); UiExceptionHelper.CheckNotNull(args, "args"); posEndingParenthesis = args.Input.LastIndexOf(")"); posOpeningParenthesis = args.Input.LastIndexOf("("); if (posEndingParenthesis == -1 || posOpeningParenthesis == -1 || posOpeningParenthesis > posEndingParenthesis) return (false); endName = posOpeningParenthesis; for (i = posOpeningParenthesis - 1; i >= 0; i--) { if (args.Input[i] != ' ') break; endName = i; } posName = -1; for (i = endName - 1; i >= 0; i--) { if (args.Input[i] == ' ') break; posName = i; } // Added this test to allow for odd case where we would // otherwise include the leading "at" or "à" in name. if (posName == 0) return false; if (posName == -1) return (false); res = args.Input.Substring(posName, posEndingParenthesis - posName + 1); args.Function = res; return (true); }
/// <summary> /// Reads args.Input and try to locate a line number information. /// If a match occurs the method fills args.Line with the identified /// integer. /// </summary> /// <param name="parser">The StackTraceParser instance. The /// parameter cannot be null.</param> /// <param name="args">The RawError instance from where read and /// write Input and Line properties. The parameter cannot be null.</param> /// <returns>True if a match occurs, false otherwise.</returns> public bool TryParse(StackTraceParser parser, RawError args) { int posTrailingColon; int line; UiExceptionHelper.CheckNotNull(parser, "parser"); UiExceptionHelper.CheckNotNull(args, "args"); if ((posTrailingColon = args.Input.LastIndexOf(":")) == -1) return (false); if ((line = lookForLastInteger(args.Input, posTrailingColon)) <= 0) return (false); args.Line = line; return (true); }
public TestIErrorParser() { _stack = new StackTraceParser(); return; }
public void SetUp() { _parser = new StackTraceParser(); return; }
private ErrorItem PopulateList(string stackTrace) { StackTraceParser parser = new StackTraceParser(); ErrorItem candidate; _stackTrace = stackTrace; parser.Parse(stackTrace); if (_listOrder == ErrorListOrderPolicy.ReverseOrder) parser.Items.Reverse(); candidate = null; _items.Clear(); foreach (ErrorItem item in parser.Items) { if (candidate == null && item.HasSourceAttachment) candidate = item; _items.Add(item); } return (candidate); }
public async Task <string> ReTrace() { var stacktrace = await new StreamReader(Request.Body).ReadToEndAsync(); return(StackTraceParser.ReTrace(_sourceMaps, stacktrace, $"{Request.Scheme}://{Request.Host}{Request.PathBase}/")); }
private static void WriteException(this StandardStreamWriter output, Exception exception, int indentLevel) { Type exceptionType = exception.GetType(); string indentationShared = new(' ', 4 * indentLevel); string indentationLocal = new(' ', 2); // Fully qualified exception type output.Write(indentationShared); output.WithForegroundColor(ConsoleColor.DarkGray, (o) => { o.Write(exceptionType.Namespace); o.Write('.'); }); output.WithForegroundColor(ConsoleColor.White, (o) => o.Write(exceptionType.Name)); output.Write(": "); // Exception message output.WithForegroundColor(ConsoleColor.Red, (o) => o.WriteLine(exception.Message)); // Recurse into inner exceptions if (exception.InnerException is not null) { output.WriteException(exception.InnerException, indentLevel + 1); } if (exception.StackTrace is null) { return; } // Try to parse and pretty-print the stack trace try { foreach (StackFrame stackFrame in StackTraceParser.ParseMany(exception.StackTrace)) { output.Write(indentationShared); output.Write(indentationLocal); output.WithForegroundColor(ConsoleColor.Green, (o) => o.Write("at ")); // "Typin.Demo.Commands.BookAddCommand." output.WithForegroundColor(ConsoleColor.DarkGray, (o) => { o.Write(stackFrame.ParentType); o.Write('.'); }); // "ExecuteAsync" output.WithForegroundColor(ConsoleColor.Yellow, (o) => o.Write(stackFrame.MethodName)); output.Write('('); for (int i = 0; i < stackFrame.Parameters.Count; ++i) { StackFrameParameter parameter = stackFrame.Parameters[i]; // "IConsole" output.WithForegroundColor(ConsoleColor.Blue, (o) => o.Write(parameter.Type)); if (!string.IsNullOrWhiteSpace(parameter.Name)) { output.Write(' '); // "console" output.WithForegroundColor(ConsoleColor.White, (o) => o.Write(parameter.Name)); } // Separator if (stackFrame.Parameters.Count > 1 && i < stackFrame.Parameters.Count - 1) { output.Write(", "); } } output.Write(") "); // Location if (!string.IsNullOrWhiteSpace(stackFrame.FilePath)) { output.WithForegroundColor(ConsoleColor.Magenta, (o) => o.Write("in")); output.WriteLine(); output.Write(indentationShared); output.Write(indentationLocal); output.Write(indentationLocal); // "C:\Projects\Typin\Typin.Demo\Commands\" var stackFrameDirectoryPath = Path.GetDirectoryName(stackFrame.FilePath); output.WithForegroundColor(ConsoleColor.DarkGray, (o) => { o.Write(stackFrameDirectoryPath); o.Write(Path.DirectorySeparatorChar); }); // "BookAddCommand.cs" string stackFrameFileName = Path.GetFileName(stackFrame.FilePath) ?? string.Empty; output.WithForegroundColor(ConsoleColor.Cyan, (o) => o.Write(stackFrameFileName)); if (!string.IsNullOrWhiteSpace(stackFrame.LineNumber)) { output.Write(':'); // "35" output.WithForegroundColor(ConsoleColor.Magenta, (o) => o.Write(stackFrame.LineNumber)); } } output.WriteLine(); } } // If any point of parsing has failed - print the stack trace without any formatting catch { output.WriteLine(exception.StackTrace); } }