Skip to content

Commit 24fae61

Browse files
committed
Improve error handling
1 parent 688688e commit 24fae61

File tree

1 file changed

+28
-3
lines changed
  • workflow-trace-viewer/src/jvmMain/kotlin/com/squareup/workflow1/traceviewer/util/parser

1 file changed

+28
-3
lines changed

workflow-trace-viewer/src/jvmMain/kotlin/com/squareup/workflow1/traceviewer/util/parser/TraceParser.kt

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.squareup.workflow1.traceviewer.util.parser
22

3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.layout.padding
35
import androidx.compose.material.Text
46
import androidx.compose.runtime.Composable
57
import androidx.compose.runtime.LaunchedEffect
@@ -11,6 +13,9 @@ import androidx.compose.runtime.remember
1113
import androidx.compose.runtime.setValue
1214
import androidx.compose.ui.Modifier
1315
import androidx.compose.ui.geometry.Offset
16+
import androidx.compose.ui.graphics.Color
17+
import androidx.compose.ui.unit.dp
18+
import androidx.compose.ui.unit.sp
1419
import com.squareup.moshi.JsonAdapter
1520
import com.squareup.workflow1.traceviewer.TraceMode
1621
import com.squareup.workflow1.traceviewer.model.Node
@@ -46,7 +51,6 @@ internal fun RenderTrace(
4651
frames.addAll(frame)
4752
fullTree.addAll(tree)
4853
affectedNodes.addAll(affected)
49-
isLoading = false
5054
onFileParse(frame.size)
5155
}
5256

@@ -73,6 +77,7 @@ internal fun RenderTrace(
7377
rawRenderPass?.let { onNewData(it) }
7478
}
7579
}
80+
isLoading = false
7681
}
7782

7883
LaunchedEffect(traceSource) {
@@ -100,8 +105,18 @@ internal fun RenderTrace(
100105
}
101106
}
102107

103-
if (error != null) {
104-
Text("Error parsing: $error")
108+
// This will only happen in the initial switch to Live Mode, where a socket error bubbled up and
109+
// the lambda call to parse the data was immediately cancelled, meaning handleParseResult was never
110+
// called to set isLoading to false
111+
if (isLoading && error != null) {
112+
Text("Socket Error: $error")
113+
return
114+
}
115+
116+
// This meant that there was an exception, but it was stored in ParseResult and read in
117+
// handleParseResult. Since there is no parsed data, this likely means there was a moshi parsing error
118+
if (error != null && frames.isEmpty()) {
119+
Text("Malformed File: $error")
105120
return
106121
}
107122

@@ -115,5 +130,15 @@ internal fun RenderTrace(
115130
onNodeSelect = onNodeSelect,
116131
storeNodeLocation = storeNodeLocation
117132
)
133+
134+
// This error happens when there has already been previous data parsed, but some exception bubbled
135+
// up again, meaning it has to be a socket closure in Live mode.
136+
error?.let {
137+
Text(
138+
text = "Socket closed: $error",
139+
fontSize = 20.sp,
140+
modifier = modifier.background(Color.White).padding(20.dp)
141+
)
142+
}
118143
}
119144
}

0 commit comments

Comments
 (0)