From 067780e1284ef8542fcc649ad22bfe734e24f99c Mon Sep 17 00:00:00 2001 From: thomabr Date: Thu, 17 Nov 2016 11:53:45 -0800 Subject: [PATCH 1/2] Have IStackFrameDeminifier.DeminifyStackFrame return a StackFrameDeminificationResult to report error cases when deminifying a StackFrame (#33) * Keep track of any error cases encountered when attempting to deminify a StackFrame. Instead of returning a list of StackFrames in DeminifyStackTraceResult, we will return a StackFrameDeminificationResult, which contains the deminified StackFrame as well as an enum indicating if any error cases were hit. This result can be used to help provide information of any error cases in the SourceMapToolkit without having to debug. * Updating documentation. * Missed merges * Add back StackFrameDeminifierUnitTests with test coverage to make sure StackFrameDeminificationResults are recorded correctly. * Undo hint path for nuget packages from local box * Fix up SourceMapToolkil csproj * Documentation cleanup * fix type in documentation * Do not do Bitwise or on DeminificationError, since the Flags attribute was removed in a previous commit. Additionally update the NoFunctionMapProvided error to be NoSourceCodeProvided since FunctionMap is not * If we fail to get the deminified stackframe method, we shouldn't attempt to get the source position or file path --- README.md | 2 +- .../DeminifyStackTraceResult.cs | 2 +- .../IStackFrameDeminifier.cs | 4 +- .../SimpleStackFrameDeminifier.cs | 18 +- ...ourcemapToolkit.CallstackDeminifier.csproj | 7 +- .../StackFrameDeminificationResult.cs | 61 +++++ .../StackFrameDeminifier.cs | 32 ++- .../StackTraceDeminifier.cs | 4 +- .../packages.config | 2 +- .../SourcemapToolkit.CallstackTestApp.csproj | 2 + .../packages.config | 2 +- ...olkit.CallstackDeminifier.UnitTests.csproj | 1 + .../StackFrameDeminifierUnitTests.cs | 226 ++++++++++++++++++ ...tackTraceDeminifierClosureEndToEndTests.cs | 11 +- .../StackTraceDeminifierEndToEndTests.cs | 13 +- .../StackTraceDeminifierUnitTests.cs | 14 +- 16 files changed, 364 insertions(+), 37 deletions(-) create mode 100644 src/SourceMapToolkit.CallstackDeminifier/StackFrameDeminificationResult.cs create mode 100644 tests/SourcemapToolkit.CallstackDeminifier.UnitTests/StackFrameDeminifierUnitTests.cs diff --git a/README.md b/README.md index 38e2ed9..428187e 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ StackTraceDeminifier sourceMapCallstackDeminifier = StackTraceDeminfierFactory.G DeminifyStackTraceResult deminifyStackTraceResult = sourceMapCallstackDeminifier.DeminifyStackTrace(callstack) ``` -The result of `DeminifyStackTrace` is a `DeminifyStackTraceResult`, which is an object that contains a list of the parsed minified `StackFrame` objects in the `MinifiedStackFrame` property. The `DeminifiedStackFrame` property contains the best guess `StackFrame` object that maps to the `MinifiedStackFrame` element with the same index. Note that any of the properties on a `StackTrace` object may be null if no value could be extracted from the input callstack string or source map. +The result of `DeminifyStackTrace` is a `DeminifyStackTraceResult`, which is an object that contains a list of `StackFrameDeminificationResults` which contains the parsed minified `StackFrame` objects in the `MinifiedStackFrame` property and an enum indicating if any errors occured when attempting to deminify the `StackFrame`. The `DeminifiedStackFrame` property contains the best guess `StackFrame` object that maps to the `MinifiedStackFrame` element with the same index. Note that any of the properties on a `StackTrace` object may be null if no value could be extracted from the input callstack string or source map. #### Memory Consumption Parsed soure maps can take up a lot of memory for large JavaScript files. In order to allow for the `StackTraceDeminifier` to be used on servers with limited memory resources, the `StackTraceDeminfierFactory` exposes a `GetMethodNameOnlyStackTraceDeminfier` method that returns a `StackTraceDeminifier` that does not keep source maps in memory. Since the `StackTraceDeminifier` returned from this method only reads the source map once, the deminified stack frames will only contain the deminified method name and will not contain the original source location. diff --git a/src/SourceMapToolkit.CallstackDeminifier/DeminifyStackTraceResult.cs b/src/SourceMapToolkit.CallstackDeminifier/DeminifyStackTraceResult.cs index b294035..70ef4d7 100644 --- a/src/SourceMapToolkit.CallstackDeminifier/DeminifyStackTraceResult.cs +++ b/src/SourceMapToolkit.CallstackDeminifier/DeminifyStackTraceResult.cs @@ -6,6 +6,6 @@ namespace SourcemapToolkit.CallstackDeminifier { public List MinifiedStackFrames; - public List DeminifiedStackFrames; + public List DeminifiedStackFrameResults; } } diff --git a/src/SourceMapToolkit.CallstackDeminifier/IStackFrameDeminifier.cs b/src/SourceMapToolkit.CallstackDeminifier/IStackFrameDeminifier.cs index 9cf3b6f..97a48eb 100644 --- a/src/SourceMapToolkit.CallstackDeminifier/IStackFrameDeminifier.cs +++ b/src/SourceMapToolkit.CallstackDeminifier/IStackFrameDeminifier.cs @@ -5,7 +5,7 @@ /// /// This method will deminify a single stack from from a minified stack trace. /// - /// Returns a stack trace that has been translated to the original source code. Returns null if it could not be deminified. - StackFrame DeminifyStackFrame(StackFrame stackFrame); + /// Returns a StackFrameDeminificationResult that contains a stack trace that has been translated to the original source code. The DeminificationError Property indicates if the StackFrame could not be deminified. DeminifiedStackFrame will not be null, but any properties of DeminifiedStackFrame could be null if the value could not be extracted. + StackFrameDeminificationResult DeminifyStackFrame(StackFrame stackFrame); } } \ No newline at end of file diff --git a/src/SourceMapToolkit.CallstackDeminifier/SimpleStackFrameDeminifier.cs b/src/SourceMapToolkit.CallstackDeminifier/SimpleStackFrameDeminifier.cs index 0f2ffc0..79a5b27 100644 --- a/src/SourceMapToolkit.CallstackDeminifier/SimpleStackFrameDeminifier.cs +++ b/src/SourceMapToolkit.CallstackDeminifier/SimpleStackFrameDeminifier.cs @@ -19,8 +19,12 @@ namespace SourcemapToolkit.CallstackDeminifier /// /// This method will deminify the method name of a single stack from from a minified stack trace. /// - public virtual StackFrame DeminifyStackFrame(StackFrame stackFrame) + public virtual StackFrameDeminificationResult DeminifyStackFrame(StackFrame stackFrame) { + StackFrameDeminificationResult result = new StackFrameDeminificationResult + { + DeminificationError = DeminificationError.None + }; if (stackFrame == null) { throw new ArgumentNullException(nameof(stackFrame)); @@ -36,9 +40,19 @@ namespace SourcemapToolkit.CallstackDeminifier { wrappingFunction = _functionMapConsumer.GetWrappingFunctionForSourceLocation(stackFrame.SourcePosition, functionMap); + + if (wrappingFunction == null) + { + result.DeminificationError = DeminificationError.NoWrapingFunctionFound; + } + } + else + { + result.DeminificationError = DeminificationError.NoSourceCodeProvided; } - return new StackFrame {MethodName = wrappingFunction?.DeminfifiedMethodName}; + result.DeminifiedStackFrame = new StackFrame {MethodName = wrappingFunction?.DeminfifiedMethodName}; + return result; } } } \ No newline at end of file diff --git a/src/SourceMapToolkit.CallstackDeminifier/SourcemapToolkit.CallstackDeminifier.csproj b/src/SourceMapToolkit.CallstackDeminifier/SourcemapToolkit.CallstackDeminifier.csproj index d6cbb69..1ae1ab8 100644 --- a/src/SourceMapToolkit.CallstackDeminifier/SourcemapToolkit.CallstackDeminifier.csproj +++ b/src/SourceMapToolkit.CallstackDeminifier/SourcemapToolkit.CallstackDeminifier.csproj @@ -51,6 +51,7 @@ + @@ -74,15 +75,15 @@ - - - {69FD1EB5-32F2-4759-9187-9A8E25927BCA} SourcemapToolkit.SourcemapParser + + +