-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SwiftRestrictedErrorInfo to preserve Swift errors across WinRT bo…
…undaries.
- Loading branch information
1 parent
3252fb8
commit e66a03a
Showing
4 changed files
with
107 additions
and
5 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
Support/Sources/WindowsRuntime/SwiftRestrictedErrorInfo.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import COM | ||
|
||
// Wraps a Swift Error object into an `IRestrictedErrorInfo` to preserve it across WinRT boundaries. | ||
internal final class SwiftRestrictedErrorInfo: COMPrimaryExport<IRestrictedErrorInfoProjection>, | ||
IRestrictedErrorInfoProtocol, IErrorInfoProtocol { | ||
override class var implements: [COMImplements] { [ | ||
.init(IErrorInfoProjection.self) | ||
] } | ||
|
||
public let error: any Error | ||
|
||
public init(error: any Error) { | ||
self.error = error | ||
} | ||
|
||
public var hresult: HResult { (self.error as? COMError)?.hresult ?? HResult.fail } | ||
public var message: String { String(describing: error) } | ||
|
||
// IErrorInfo | ||
public var guid: GUID { get throws { throw HResult.Error.fail } } | ||
public var source: String? { get throws { throw HResult.Error.fail } } | ||
public var description: String? { self.message } | ||
public var helpFile: String? { get throws { throw HResult.Error.fail } } | ||
public var helpContext: UInt32 { get throws { throw HResult.Error.fail } } | ||
|
||
// IRestrictedErrorInfo | ||
public func getErrorDetails( | ||
description: inout String?, | ||
error: inout HResult, | ||
restrictedDescription: inout String?, | ||
capabilitySid: inout String?) throws { | ||
description = self.description | ||
error = self.hresult | ||
restrictedDescription = description | ||
capabilitySid = nil | ||
} | ||
|
||
public var reference: String? { get throws { throw HResult.Error.fail } } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 17 additions & 1 deletion
18
Support/Sources/WindowsRuntime_ABI/include/SWRT/windows/roerrorapi.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
#pragma once | ||
|
||
#include <stdbool.h> | ||
#include "SWRT/windows/unknwn.h" | ||
#include "SWRT/windows/restrictederrorinfo.h" | ||
#include "SWRT/windows/winstring.h" | ||
|
||
typedef enum { | ||
SWRT_RO_ERROR_REPORTING_NONE = 0x00000000, | ||
SWRT_RO_ERROR_REPORTING_SUPPRESSEXCEPTIONS = 0x00000001, | ||
SWRT_RO_ERROR_REPORTING_FORCEEXCEPTIONS = 0x00000002, | ||
SWRT_RO_ERROR_REPORTING_USESETERRORINFO = 0x00000004, | ||
SWRT_RO_ERROR_REPORTING_SUPPRESSSETERRORINFO = 0x00000008, | ||
} SWRT_RO_ERROR_REPORTING_FLAGS; | ||
|
||
SWRT_HResult SWRT_GetRestrictedErrorInfo(SWRT_IRestrictedErrorInfo** ppRestrictedErrorInfo); | ||
SWRT_HResult SWRT_RoCaptureErrorContext(SWRT_HResult hr); | ||
void SWRT_RoClearError(); | ||
void SWRT_RoFailFastWithErrorContext(SWRT_HResult hrError); | ||
SWRT_HResult SWRT_RoGetErrorReportingFlags(uint32_t* pflags); | ||
SWRT_HResult SWRT_RoGetMatchingRestrictedErrorInfo(SWRT_HResult hrIn, SWRT_IRestrictedErrorInfo** ppRestrictedErrorInfo); | ||
bool SWRT_RoOriginateError(SWRT_HResult error, SWRT_HString message); | ||
bool SWRT_RoOriginateErrorW(SWRT_HResult error, uint32_t cchMax, const char16_t* message); | ||
bool SWRT_RoOriginateErrorW(SWRT_HResult error, uint32_t cchMax, const char16_t* message); | ||
bool SWRT_RoOriginateLanguageException(SWRT_HResult error, SWRT_HString message, SWRT_IUnknown* languageException); | ||
SWRT_HResult SWRT_RoReportUnhandledError(SWRT_IRestrictedErrorInfo* pRestrictedErrorInfo); | ||
SWRT_HResult SWRT_RoSetErrorReportingFlags(uint32_t flags); | ||
SWRT_HResult SWRT_RoTransformError(SWRT_HResult oldError, SWRT_HResult newError, SWRT_HString message); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters