Skip to content

Commit 1389a6b

Browse files
authored
Merge pull request #1310 from square/ray/no-id-hashes-in-group-keys
Better choices for `stackTraceKey`
2 parents 54e0b46 + 22432fa commit 1389a6b

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

workflow-core/src/commonMain/kotlin/com/squareup/workflow1/WorkerWorkflow.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ internal class WorkerWorkflow<OutputT>(
4040
unsnapshottableIdentifier(workerType)
4141
}
4242

43-
override fun describeRealIdentifier(): String = workerType.toString()
43+
override fun describeRealIdentifier(): String =
44+
workerType.toString().replace(" (Kotlin reflection is not available)", "")
4445

4546
override fun initialState(
4647
props: Worker<OutputT>,

workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/RealRenderContext.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ internal class RealRenderContext<out PropsT, StateT, OutputT>(
7272
key: String,
7373
handler: (ChildOutputT) -> WorkflowAction<PropsT, StateT, OutputT>
7474
): ChildRenderingT {
75-
checkNotFrozen(child) { "renderChild(${child.identifier})" }
75+
checkNotFrozen(child.identifier) {
76+
"renderChild(${child.identifier})"
77+
}
7678
return renderer.render(child, props, key, handler)
7779
}
7880

@@ -111,6 +113,7 @@ internal class RealRenderContext<out PropsT, StateT, OutputT>(
111113

112114
/**
113115
* @param stackTraceKey ensures unique crash reporter error groups.
116+
* It is important that keys are stable across processes, avoid system hashes.
114117
*
115118
* @see checkWithKey
116119
*/

workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/SubtreeManager.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ internal class SubtreeManager<PropsT, StateT, OutputT>(
126126
// Prevent duplicate workflows with the same key.
127127
workflowTracer.trace("CheckingUniqueMatches") {
128128
children.forEachStaging {
129-
requireWithKey(!(it.matches(child, key, workflowTracer)), stackTraceKey = child) {
130-
"Expected keys to be unique for ${child.identifier}: key=\"$key\""
131-
}
129+
requireWithKey(
130+
!(it.matches(child, key, workflowTracer)),
131+
stackTraceKey = child.identifier
132+
) { "Expected keys to be unique for ${child.identifier}: key=\"$key\"" }
132133
}
133134
}
134135

workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/Throwables.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import kotlin.contracts.contract
1010
*
1111
* So far [stackTraceKey] is only effective on JVM, it has no effect in other languages.
1212
*
13+
* @param stackTraceKey an object whose [toString] method will serve as a grouping key
14+
* for crash reporters. It is important that keys are stable across processes,
15+
* avoid system hashes.
16+
*
1317
* @see [withKey]
1418
*
1519
* @throws IllegalArgumentException if the [value] is false.
@@ -37,6 +41,10 @@ internal inline fun requireWithKey(
3741
*
3842
* So far [stackTraceKey] is only effective on JVM, it has no effect in other languages.
3943
*
44+
* @param stackTraceKey an object whose [toString] method will serve as a grouping key
45+
* for crash reporters. It is important that keys are stable across processes,
46+
* avoid system hashes.
47+
*
4048
* @see [withKey]
4149
*
4250
* @throws IllegalStateException if the [value] is false.
@@ -62,5 +70,9 @@ internal inline fun checkWithKey(
6270
* that crash reporter's default grouping will create unique groups for unique keys.
6371
*
6472
* So far only effective on JVM, this is a pass through in other languages.
73+
*
74+
* @param stackTraceKey an object whose [toString] method will serve as a grouping key
75+
* for crash reporters. It is important that keys are stable across processes,
76+
* avoid system hashes.
6577
*/
6678
internal expect fun <T : Throwable> T.withKey(stackTraceKey: Any): T

0 commit comments

Comments
 (0)