apple / apple/swift-log

Logging function autoclosures aren't "rethrows"

Open
#265 8 comments 0 reactions 0 assignees View on GitHub
⚠️ semver/major
Dominant language
Swift
Stars
4k
Forks
344
Avg merge
1d 11h
Merged PRs (30d)
5

Description

### Expected behavior
If I have a throwing function `fn()` or a throwing property accessor, it would be nice if these two log statements work:

try logger.info("calling fn = \(fn())")
try logger.info("value of property = \(object.property)")

### Actual behavior
Right now it does not compile, giving the error `Property access can throw, but it is executed in a non-throwing autoclosure`.

I believe marking the autoclosures with `rethrows` will resolve this problem.

### Steps to reproduce

1. Per above, `try` a logging function with a string interpolation containing a throwing function call or property access.

### If possible, minimal yet complete reproducer code (or URL to code)

I can provide something if it's really necessary, but I think there is enough information above.

### SwiftLog version/commit hash

1.5.2

### Swift & OS version (output of `swift --version && uname -a`)

swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0
Darwin smadsen-MacBook-Pro 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 arm64

Contributor guide

Open the contributing guide

Research direction

Start by locating the logging functions that accept message autoclosures and reproduce the reported examples with throwing functions and property accessors. Check how existing logging tests cover autoclosures; done means both `try logger.info` forms compile and the behavior is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.