Skip to content

Commit

Permalink
unimplemented support for typed throws
Browse files Browse the repository at this point in the history
This adds `unimplemented` support for endpoints using typed throws.
  • Loading branch information
stephencelis committed Aug 19, 2024
1 parent 9829b6a commit 2b76fc2
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- ``unimplemented(_:fileID:filePath:function:line:column:)-2ae22``
- ``unimplemented(_:fileID:filePath:function:line:column:)-1hsov``
- ``unimplemented(_:throwing:fileID:filePath:function:line:column:)-4h958``
- ``unimplemented(_:throwing:fileID:filePath:function:line:column:)-5zfy9``
- ``unimplemented(_:placeholder:fileID:filePath:function:line:column:)-6ts5j``
- ``unimplemented(_:placeholder:fileID:filePath:function:line:column:)-34tpp``

Expand Down
80 changes: 80 additions & 0 deletions Sources/IssueReporting/Unimplemented.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,45 @@ public func unimplemented<each Argument, Result>(
}
}

/// Returns a throwing closure that reports an issue and throws a given error when invoked.
///
/// Useful for creating closures that need to be overridden by users of your API, and if it is
/// ever invoked without being overridden an issue will be reported. See
/// <doc:GettingStarted#Unimplemented-closures> for more information.
///
/// - Parameters:
/// - description: An optional description of the unimplemented closure.
/// - failure: The error thrown by the unimplemented closure.
/// - fileID: The fileID.
/// - filePath: The filePath.
/// - function: The function.
/// - line: The line.
/// - column: The column.
/// - Returns: A throwing closure that reports an issue and throws an error when invoked.
public func unimplemented<each Argument, Failure: Error, Result>(
_ description: @autoclosure @escaping @Sendable () -> String = "",
throwing failure: @autoclosure @escaping @Sendable () -> Failure,
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
function: StaticString = #function,
line: UInt = #line,
column: UInt = #column
) -> @Sendable (repeat each Argument) throws(Failure) -> Result {
return { (argument: repeat each Argument) throws(Failure) in
let description = description()
_fail(
description,
(repeat each argument),
fileID: fileID,
filePath: filePath,
function: function,
line: line,
column: column
)
throw failure()
}
}

/// Returns an asynchronous closure that reports an issue when invoked.
///
/// Useful for creating closures that need to be overridden by users of your API, and if it is
Expand Down Expand Up @@ -149,6 +188,47 @@ public func unimplemented<each Argument, Result>(
}
}

/// Returns a throwing, asynchronous closure that reports an issue and throws a given error when
/// invoked.
///
/// Useful for creating closures that need to be overridden by users of your API, and if it is
/// ever invoked without being overridden an issue will be reported. See
/// <doc:GettingStarted#Unimplemented-closures> for more information.
///
/// - Parameters:
/// - description: An optional description of the unimplemented closure.
/// - failure: The error thrown by the unimplemented closure.
/// - fileID: The fileID.
/// - filePath: The filePath.
/// - function: The function.
/// - line: The line.
/// - column: The column.
/// - Returns: A throwing, asynchronous closure that reports an issue and throws an error when
/// invoked.
public func unimplemented<each Argument, Failure: Error, Result>(
_ description: @autoclosure @escaping @Sendable () -> String = "",
throwing failure: @autoclosure @escaping @Sendable () -> Failure,
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
function: StaticString = #function,
line: UInt = #line,
column: UInt = #column
) -> @Sendable (repeat each Argument) async throws(Failure) -> Result {
return { (argument: repeat each Argument) async throws(Failure) in
let description = description()
_fail(
description,
(repeat each argument),
fileID: fileID,
filePath: filePath,
function: function,
line: line,
column: column
)
throw failure()
}
}

@_disfavoredOverload
public func unimplemented<Result>(
_ description: @autoclosure @escaping @Sendable () -> String = "",
Expand Down

0 comments on commit 2b76fc2

Please sign in to comment.