|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Diagnostics; |
4 | | -using System.IO; |
5 | 4 |
|
6 | 5 | namespace Backtrace.Unity.Model |
7 | 6 | { |
@@ -45,47 +44,36 @@ private void ConvertStackFrames() |
45 | 44 | var frames = _stacktrace.Trim().Split('\n'); |
46 | 45 | foreach (var frameString in frames) |
47 | 46 | { |
48 | | - using (var outputFile = new StreamWriter(Path.Combine(@"C:\Users\konra\source\BacktraceLogs\", $"errors-unhandled-stacktrace.txt"), true)) |
| 47 | + int methodNameEndIndex = frameString.IndexOf(')'); |
| 48 | + //methodname index should be greater than 0 AND '(' should be before ')' |
| 49 | + if (methodNameEndIndex < 1 && frameString[methodNameEndIndex - 1] != '(') |
49 | 50 | { |
50 | | - try |
51 | | - { |
52 | | - outputFile.WriteLine("STACK FRAME : " + frameString.ToString()); |
53 | | - int methodNameEndIndex = frameString.IndexOf(')'); |
54 | | - //methodname index should be greater than 0 AND '(' should be before ')' |
55 | | - if (methodNameEndIndex < 1 && frameString[methodNameEndIndex - 1] != '(') |
56 | | - { |
57 | | - //invalid stack frame |
58 | | - return; |
59 | | - } |
60 | | - string routingPaths = frameString.Substring(0, methodNameEndIndex - 1); |
61 | | - var routingParams = routingPaths.Trim().Split('.'); |
62 | | - string methodPath = string.Empty; |
63 | | - int fileLine = 0; |
| 51 | + //invalid stack frame |
| 52 | + return; |
| 53 | + } |
| 54 | + string routingPaths = frameString.Substring(0, methodNameEndIndex - 1); |
| 55 | + var routingParams = routingPaths.Trim().Split('.'); |
| 56 | + string methodPath = string.Empty; |
| 57 | + int fileLine = 0; |
64 | 58 |
|
65 | | - int sourceInformationStartIndex = frameString.IndexOf('(', methodNameEndIndex + 1); |
66 | | - if (sourceInformationStartIndex > -1) |
67 | | - { |
68 | | - // -1 because we don't want additional ')' in the end of the string |
69 | | - int sourceStringLength = frameString.Length - sourceInformationStartIndex - 1; |
70 | | - string sourceString = |
71 | | - frameString.Substring(sourceInformationStartIndex, sourceStringLength); |
72 | | - var sourceInfo = sourceString.Split(':'); |
73 | | - methodPath = sourceInfo[0].Substring(sourceInfo[0].IndexOf(' ')); |
74 | | - int.TryParse(sourceInfo[1], out fileLine); |
75 | | - } |
76 | | - StackFrames.Add(new BacktraceStackFrame() |
77 | | - { |
78 | | - FunctionName = routingParams[1], |
79 | | - Library = routingParams[0], |
80 | | - Line = fileLine, |
81 | | - SourceCode = methodPath |
82 | | - }); |
83 | | - } |
84 | | - catch(Exception e) |
85 | | - { |
86 | | - outputFile.WriteLine(e.ToString()); |
87 | | - } |
| 59 | + int sourceInformationStartIndex = frameString.IndexOf('(', methodNameEndIndex + 1); |
| 60 | + if (sourceInformationStartIndex > -1) |
| 61 | + { |
| 62 | + // -1 because we don't want additional ')' in the end of the string |
| 63 | + int sourceStringLength = frameString.Length - sourceInformationStartIndex - 1; |
| 64 | + string sourceString = |
| 65 | + frameString.Substring(sourceInformationStartIndex, sourceStringLength); |
| 66 | + var sourceInfo = sourceString.Split(':'); |
| 67 | + methodPath = sourceInfo[0].Substring(sourceInfo[0].IndexOf(' ')); |
| 68 | + int.TryParse(sourceInfo[1], out fileLine); |
88 | 69 | } |
| 70 | + StackFrames.Add(new BacktraceStackFrame() |
| 71 | + { |
| 72 | + FunctionName = routingParams[1], |
| 73 | + Library = routingParams[0], |
| 74 | + Line = fileLine, |
| 75 | + SourceCode = methodPath |
| 76 | + }); |
89 | 77 |
|
90 | 78 | } |
91 | 79 | } |
|
0 commit comments