This gives you not just a way to side-step the error system, but makes it the default. This can be a pretty serious and hard-to-find problem. A common workaround is to opt-in to some more safety by using an explicit Task<Void, Never>.
This is what the signature in question looks like today:
extension Task where Failure == any Error {
@discardableResult
public init(priority: TaskPriority? = nil, operation: sending @escaping @isolated(any) () async throws -> Success)
}
I'd like to propose changing this to remove the @discardableResult. This would just make ignoring errors opt-in, instead of opt-out.
I think the warning this would introduce will also certainly result in uncovering unintentional bugs. I looked though swift-evolution/proposals/0304-structured-concurrency.md at main · swiftlang/swift-evolution · GitHub, and I didn't find a lot of justification for why this particular version should be discardable. So, given how many people have had trouble with this, I thought it could be worth revisiting.
FWIW, I just always type Task<Void, Never> now rather than just Task and any time I see Task I hear alarm bells. Seems to me like something that would be great to improve.
I think we had that pitched as part of some earlier proposal that just didn’t happen because it’s scope probably included typed throws adoption AFAIR.
Personally I’m supportive of this and it’s worth a proposal review I think.
I would probably adopt typed throws in Task.init and detached in the same proposal and call it some “improved error handling in unstructured tasks”.
Adopting typed throws in other parts of the stdlib is going to be hard but this specific api we can do right now, I think I even have it prepared on a PR tbh.
Hi! I started that original thread two years ago, and got notified when it was cross-referenced just now.
In that time, I have not changed my position on this. It would be great to get a warning for this, which is all I want, and this pitch would give me exactly that. I support this!
@mattie how about we work on a real proposal (as a PR to the evolution repo), but perhaps let's include the typed throws adoption for Task.init and Task.detached. It'd be nice if you can take the initiative on the proposal and I can provide help with the implementation and review etc.