Skip to content

Commit

Permalink
Added support for FACILITY_WINCODEC_DWRITE_DWM
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasArdal committed Jul 19, 2024
1 parent 5bc2985 commit c40f9cb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Elmah.Io.HResults.Facilities
{
// Sources:
// - https://learn.microsoft.com/en-us/troubleshoot/developer/dotnet/framework/general/wpf-render-thread-failures
internal class FacilityWincodecDwriteDwmResolver : FacilityResolverBase
{
public FacilityWincodecDwriteDwmResolver() : base(2200, "FACILITY_WINCODEC_DWRITE_DWM")
{
}

internal override Code Resolve(bool failure, int code)
{
return code switch
{
1030 => new Code(code, "UCEERR_RENDERTHREADFAILURE"),
_ => Unknown(code),
};
}
}
}
2 changes: 1 addition & 1 deletion src/Elmah.Io.HResults/IntExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal static class IntExtensions
new FacilityScardResolver(), new FacilitySecurityResolver(), new FacilitySetupapiResolver(),
new FacilityStorageResolver(), new FacilityTpmServicesResolver(), new FacilityTpmSoftwareResolver(),
new FacilityUrtResolver(), new FacilityUsermodeFilterManagerResolver(), new FacilityWin32Resolver(),
new FacilityWindowsResolver(), new FacilityControlResolver()
new FacilityWindowsResolver(), new FacilityControlResolver(), new FacilityWincodecDwriteDwmResolver()
};

internal static Code ToCode(this int code, bool failure, int facility)
Expand Down
46 changes: 10 additions & 36 deletions test/Elmah.Io.HResults.Test/HResultTest.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,27 @@
using NUnit.Framework;
using System;
using System.Globalization;

namespace Elmah.Io.HResults.Test
{
public class HResultTest
{
[TestCase("FACILITY_CONTROL", "CTL_E_ILLEGALFUNCTIONCALL", -2146828283)]
public void CanParseFacility(string expectedFacitliy, string expectedCode, int hresult)
[TestCase(-2003303418, "0x88980406", 2200, "FACILITY_WINCODEC_DWRITE_DWM", 1030, "UCEERR_RENDERTHREADFAILURE")]
[TestCase(-2147024894, "0x80070002", 7, "FACILITY_WIN32", 2, "ERROR_FILE_NOT_FOUND")]
[TestCase(-2146232832, "0x80131600", 19, "FACILITY_URT", 5632, "COR_E_APPLICATION")]
[TestCase(-2146828283, "0x800A0005", 10, "FACILITY_CONTROL", 5, "CTL_E_ILLEGALFUNCTIONCALL")]
public void CanParseKnownFailure(int hresult, string expectedHex, int expectedFacilityCode, string expectedFacilityName, int expectedCode, string expectedName)
{
var res = HResult.Parse(hresult);
Assert.That(res.Facility.IsMatch);
Assert.That(res.Facility.Name, Is.EqualTo(expectedFacitliy));
Assert.That(res.Code.IsMatch);
Assert.That(res.Code.Name, Is.EqualTo(expectedCode));
}

[Test]
public void CanParseKnownUrt()
{
var ex = new ApplicationException();
var res = HResult.Parse(ex.HResult);
Assert.IsNotNull(res);
Assert.That(res.Hex, Is.EqualTo("0x80131600"));
Assert.That(res.IsFailure, Is.True);
Assert.That(res.Facility, Is.Not.Null);
Assert.That(res.Facility.Identifier, Is.EqualTo(19));
Assert.That(res.Facility.Name, Is.EqualTo("FACILITY_URT"));
Assert.That(res.Facility.IsMatch, Is.True);
Assert.That(res.Code, Is.Not.Null);
Assert.That(res.Code.Identifier, Is.EqualTo(5632));
Assert.That(res.Code.Name, Is.EqualTo("COR_E_APPLICATION"));
Assert.That(res.Code.IsMatch, Is.True);
}

[Test]
public void CanParseKnownWin32()
{
var res = HResult.Parse(-2147024894);
Assert.IsNotNull(res);
Assert.That(res.Hex, Is.EqualTo("0x80070002"));
Assert.That(res.Hex, Is.EqualTo(expectedHex));
Assert.That(res.IsFailure, Is.True);
Assert.That(res.Facility, Is.Not.Null);
Assert.That(res.Facility.Identifier, Is.EqualTo(7));
Assert.That(res.Facility.Name, Is.EqualTo("FACILITY_WIN32"));
Assert.That(res.Facility.Identifier, Is.EqualTo(expectedFacilityCode));
Assert.That(res.Facility.Name, Is.EqualTo(expectedFacilityName));
Assert.That(res.Facility.IsMatch, Is.True);
Assert.That(res.Code, Is.Not.Null);
Assert.That(res.Code.Identifier, Is.EqualTo(2));
Assert.That(res.Code.Name, Is.EqualTo("ERROR_FILE_NOT_FOUND"));
Assert.That(res.Code.Identifier, Is.EqualTo(expectedCode));
Assert.That(res.Code.Name, Is.EqualTo(expectedName));
Assert.That(res.Code.IsMatch, Is.True);
}

Expand Down

0 comments on commit c40f9cb

Please sign in to comment.