Crash task-local: illegal task-local value binding #110
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@corysullivan That error is due to executing task local code inside an invalid context, like within a func testIllegalTaskLocal() async {
enum Test {
@TaskLocal static var isSetting = false
}
await withTaskGroup(of: Void.self) { group in
Test.$isSetting.withValue(true) {
print(Test.isSetting)
}
print(Test.isSetting)
}
} If you follow your trace to the effect causing the crash, you're likely in a My only guess as to why you didn't encounter this issue earlier is that you were on a version of Dependencies that didn't access the task local at this time. |
Beta Was this translation helpful? Give feedback.
@corysullivan That error is due to executing task local code inside an invalid context, like within a
withTaskGroup
block but outside anaddTask
. Here's a vanilla test case demonstrating the issue:If you follow your trace to the effect causing the crash, you're likely in a
withTaskGroup
context. You'll want to avoid accessing dependencies in that scope, and instead move dependency access insidegroup.addTask
, or outside the task group ent…