Remove `throw error as! Failure` TaskLocal adopts typed throws

Open Beginner friendly
#481 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Quiet
Tech stack
swift

Research direction

Start with the withLogger implementation shown in the issue and read Swift issue 75520 for the TaskLocal typed-throws behavior. Run the project's existing tests after removing the unnecessary forced cast; done means the code compiles and the operation preserves its declared Failure type.

Written by the indexing model from the issue text.

Description

Swift issue https://github.com/swiftlang/swift/issues/75520

The code in question:

public func withLogger<Result, Failure: Error>(
    _ logger: Logger,
    _ operation: (Logger) throws(Failure) -> Result
) throws(Failure) -> Result {
    do {
        return try Logger.withTaskLocalLogger(logger) {
            try operation(logger)
        }
    } catch {
        throw error as! Failure
    }
}
Dominant language
Swift
Stars
4.1k
Forks
344
Avg merge
1d 9h
Merged PRs (30d)
6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apple/swift-log

All issues in apple/swift-log

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.