Skip to content

Commit

Permalink
More FACILITY_NULL code mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasArdal committed Nov 18, 2023
1 parent 6955a05 commit e000df9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
22 changes: 22 additions & 0 deletions src/Elmah.Io.HResults/Facilities/FacilityNullResolver.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Elmah.Io.HResults.Facilities
{
// Thank you https://learn.microsoft.com/en-us/windows/win32/com/error-handling-strategies
internal class FacilityNullResolver : FacilityResolverBase
{
public FacilityNullResolver() : base(0, "FACILITY_NULL")
Expand All @@ -8,11 +9,32 @@ public FacilityNullResolver() : base(0, "FACILITY_NULL")

internal override Code Resolve(bool failure, int code)
{
if (!failure)
{
return code switch
{
0 => new Code(code, "S_OK", "The method succeeded. If a boolean return value is expected, the returned value is TRUE."),
1 => new Code(code, "S_FALSE", "The method succeeded and returned the boolean value FALSE."),
_ => Unknown(code),
};
}

return code switch
{
1 => new Code(code, "ERROR_AUDITING_DISABLED", "The specified event is currently not being audited."),
2 => new Code(code, "ERROR_ALL_SIDS_FILTERED", "The SID filtering operation removed all SIDs."),
3 => new Code(code, "ERROR_BIZRULES_NOT_ENABLED", "Business rule scripts are disabled for the calling application."),
5 => new Code(code, "E_ACCESSDENIED", "A general access - denied error."),
6 => new Code(code, "E_HANDLE", "An invalid handle was used."),
10 => new Code(code, "E_PENDING", "The data necessary to complete the operation is not yet available."),
14 => new Code(code, "E_OUTOFMEMORY", "The method failed to allocate necessary memory."),
87 => new Code(code, "E_INVALIDARG", "One or more arguments are invalid."),
16385 => new Code(code, "E_NOTIMPL", "The method is not implemented."),
16386 => new Code(code, "E_NOINTERFACE", "The QueryInterface method did not recognize the requested interface. The interface is not supported."),
16387 => new Code(code, "E_POINTER", "An invalid pointer was used."),
16388 => new Code(code, "E_ABORT", "The operation was aborted because of an unspecified error."),
16389 => new Code(code, "E_FAIL", "An unspecified failure has occurred."),
65535 => new Code(code, "E_UNEXPECTED", "A catastrophic failure has occurred."),
_ => Unknown(code),
};
}
Expand Down
9 changes: 5 additions & 4 deletions test/Elmah.Io.HResults.Test/HResultTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,17 @@ public void CanParseKnownWin32()
[Test]
public void CanParseUnknown()
{
var res = HResult.Parse(-2147467259);
var i = int.Parse("80004006", NumberStyles.HexNumber);
var res = HResult.Parse(-2147467258);
Assert.IsNotNull(res);
Assert.That(res.Hex, Is.EqualTo("0x80004005"));
Assert.That(res.Hex, Is.EqualTo("0x80004006"));
Assert.That(res.IsFailure, Is.True);
Assert.That(res.Facility, Is.Not.Null);
Assert.That(res.Facility.Identifier, Is.EqualTo(0));
Assert.That(res.Facility.Name, Is.EqualTo("FACILITY_NULL"));
Assert.That(res.Code, Is.Not.Null);
Assert.That(res.Code.Identifier, Is.EqualTo(16389));
Assert.That(res.Code.Name, Is.EqualTo("16389"));
Assert.That(res.Code.Identifier, Is.EqualTo(16390));
Assert.That(res.Code.Name, Is.EqualTo("16390"));
}

[Test]
Expand Down

0 comments on commit e000df9

Please sign in to comment.