Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
DOTNET-199: Adjust InnerException string before the '--- End of inner…
… exception stack trace ---' line
  • Loading branch information
homiedopie committed Sep 13, 2024
commit e4105babd3ce74eb77eb47cda2bed64365d058e2
12 changes: 6 additions & 6 deletions Src/StackifyLib.log4net.Tests/StackifyLib.log4net.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,22 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=2.0.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.11\lib\net45\log4net.dll</HintPath>
<Reference Include="log4net, Version=2.0.17.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.17\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.13.2.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.13.2\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="StackifyLib, Version=2.2.15.0, Culture=neutral, PublicKeyToken=e0ba3f4d3f1bb0c2, processorArchitecture=MSIL">
<HintPath>..\packages\StackifyLib.2.2.15\lib\net452\StackifyLib.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Management" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -65,10 +69,6 @@
<Project>{7d98e5e3-a3e7-4613-8bb7-80a60d86a5e8}</Project>
<Name>StackifyLib.log4net</Name>
</ProjectReference>
<ProjectReference Include="..\StackifyLib\StackifyLib.csproj">
<Project>{03cf7411-65e2-4998-a157-9224eca6199b}</Project>
<Name>StackifyLib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
3 changes: 2 additions & 1 deletion Src/StackifyLib.log4net.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.11" targetFramework="net452" />
<package id="log4net" version="2.0.17" targetFramework="net452" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net452" />
<package id="NUnit" version="3.13.2" targetFramework="net452" />
<package id="StackifyLib" version="2.2.15" targetFramework="net452" />
</packages>
10 changes: 5 additions & 5 deletions Src/StackifyLib/Models/ErrorItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,15 @@ public string FramesToString()
{
StringBuilder sb = new StringBuilder();

foreach (var item in this.StackTrace)
if (InnerError != null)
{
sb.AppendFormat(" at {0}\r\n", item.Method);
sb.Append(InnerError.FramesToString());
sb.Append("--- End of inner exception stack trace ---\r\n");
}

if (InnerError != null)
foreach (var item in this.StackTrace)
{
sb.Append("--- End of inner exception stack trace ---\r\n");
sb.Append(InnerError.FramesToString());
sb.AppendFormat(" at {0}\r\n", item.Method);
}

return sb.ToString();
Expand Down
9 changes: 2 additions & 7 deletions Src/StackifyLibCore.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30907.101
# Visual Studio Version 17
VisualStudioVersion = 17.11.35303.130
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackifyLib", "StackifyLib\StackifyLib.csproj", "{03CF7411-65E2-4998-A157-9224ECA6199B}"
EndProject
Expand Down Expand Up @@ -71,11 +71,9 @@ Global
{D0E1AABD-6397-4CC7-9737-4904A4BF5BCD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D0E1AABD-6397-4CC7-9737-4904A4BF5BCD}.Release|Any CPU.Build.0 = Release|Any CPU
{2B832B34-BA30-4B5A-8E78-D6DC78AF16FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B832B34-BA30-4B5A-8E78-D6DC78AF16FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B832B34-BA30-4B5A-8E78-D6DC78AF16FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B832B34-BA30-4B5A-8E78-D6DC78AF16FB}.Release|Any CPU.Build.0 = Release|Any CPU
{BC6FDF2B-E063-4F8B-ABBA-6BD9425D4C64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC6FDF2B-E063-4F8B-ABBA-6BD9425D4C64}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC6FDF2B-E063-4F8B-ABBA-6BD9425D4C64}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC6FDF2B-E063-4F8B-ABBA-6BD9425D4C64}.Release|Any CPU.Build.0 = Release|Any CPU
{CB09D719-F393-413D-B5CD-E0125543AD24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand All @@ -99,15 +97,12 @@ Global
{647F27AD-13D7-40C2-A7BB-97A5D19CE3D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{647F27AD-13D7-40C2-A7BB-97A5D19CE3D5}.Release|Any CPU.Build.0 = Release|Any CPU
{ADBD2138-9DE7-4211-AF58-84C7F0F9BEA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ADBD2138-9DE7-4211-AF58-84C7F0F9BEA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ADBD2138-9DE7-4211-AF58-84C7F0F9BEA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ADBD2138-9DE7-4211-AF58-84C7F0F9BEA5}.Release|Any CPU.Build.0 = Release|Any CPU
{99C81723-20FB-4241-862C-32F7ADDB7A9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{99C81723-20FB-4241-862C-32F7ADDB7A9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99C81723-20FB-4241-862C-32F7ADDB7A9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{99C81723-20FB-4241-862C-32F7ADDB7A9B}.Release|Any CPU.Build.0 = Release|Any CPU
{EC5742DF-C1A8-4A7A-81DC-B6E0A4D3472D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC5742DF-C1A8-4A7A-81DC-B6E0A4D3472D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC5742DF-C1A8-4A7A-81DC-B6E0A4D3472D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC5742DF-C1A8-4A7A-81DC-B6E0A4D3472D}.Release|Any CPU.Build.0 = Release|Any CPU
{18F96933-468E-4104-961E-0C68A5EF2B29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down
78 changes: 78 additions & 0 deletions test/StackifyLib.UnitTests/Models/ErrorItem_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright (c) 2024 BMC Software, Inc.
// Copyright (c) 2021-2024 Netreo
// Copyright (c) 2019 Stackify
using StackifyLib.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Moq;

namespace StackifyLib.UnitTests.Models
{
public class ErrorItem_Tests
{

[Fact]
public async Task TestExceptionStringWithInnerException()
{
var expectedString = string.Join(
Environment.NewLine,
"System.Exception: Wrapping the exception to see the differences between outer and inner exceptions. ---> System.Exception: Throwing this exception to see all properties like stacktrace filled",
" at StackifyLib.UnitTests.Models.ExampleService.ThrowInnerException()",
" at StackifyLib.UnitTests.Models.ExampleService.CreateCaughtException()",
"--- End of inner exception stack trace ---",
" at StackifyLib.UnitTests.Models.ExampleService.ThrowOuterException(System.Exception)",
" at StackifyLib.UnitTests.Models.ExampleService.CreateCaughtException()",
" at StackifyLib.UnitTests.Models.ErrorItem_Tests+<TestExceptionStringWithInnerException>d__0.MoveNext()",
""
);
try
{
//ExampleService service = new ExampleService();
ExampleService.CreateCaughtException();
}
catch (Exception ex)
{
//PrintExceptionInfo(ex);
var exceptionString = new ErrorItem(ex).ToString();
Assert.Contains(expectedString, exceptionString);
}
}
}

class ExampleService
{
public static Exception CreateCaughtException()
{
try
{
try
{
ThrowInnerException();
}
catch (Exception exception)
{
ThrowOuterException(exception);
}
}
catch (Exception)
{
throw;
}
// NOTE: never reached, but needed for the compiler.
return null;
}
private static void ThrowOuterException(Exception exception)
{
throw new Exception("Wrapping the exception to see the differences between outer and inner exceptions.", exception);
}
private static void ThrowInnerException()
{
throw new Exception("Throwing this exception to see all properties like stacktrace filled");
}
}
}
2 changes: 1 addition & 1 deletion test/StackifyLib.UnitTests/StackifyLib.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.5.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1" />
Expand Down