1
1
package com.squareup.workflow1.traceviewer.util.parser
2
2
3
+ import androidx.compose.foundation.background
4
+ import androidx.compose.foundation.layout.padding
3
5
import androidx.compose.material.Text
4
6
import androidx.compose.runtime.Composable
5
7
import androidx.compose.runtime.LaunchedEffect
@@ -11,6 +13,9 @@ import androidx.compose.runtime.remember
11
13
import androidx.compose.runtime.setValue
12
14
import androidx.compose.ui.Modifier
13
15
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
14
19
import com.squareup.moshi.JsonAdapter
15
20
import com.squareup.workflow1.traceviewer.TraceMode
16
21
import com.squareup.workflow1.traceviewer.model.Node
@@ -46,7 +51,6 @@ internal fun RenderTrace(
46
51
frames.addAll(frame)
47
52
fullTree.addAll(tree)
48
53
affectedNodes.addAll(affected)
49
- isLoading = false
50
54
onFileParse(frame.size)
51
55
}
52
56
@@ -73,6 +77,7 @@ internal fun RenderTrace(
73
77
rawRenderPass?.let { onNewData(it) }
74
78
}
75
79
}
80
+ isLoading = false
76
81
}
77
82
78
83
LaunchedEffect (traceSource) {
@@ -100,8 +105,18 @@ internal fun RenderTrace(
100
105
}
101
106
}
102
107
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 " )
105
120
return
106
121
}
107
122
@@ -115,5 +130,15 @@ internal fun RenderTrace(
115
130
onNodeSelect = onNodeSelect,
116
131
storeNodeLocation = storeNodeLocation
117
132
)
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
+ }
118
143
}
119
144
}
0 commit comments