Skip to content

Commit 31acfe7

Browse files
committed
Improve connection error message
1 parent a3c4d7f commit 31acfe7

File tree

1 file changed

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

1 file changed

+22
-13
lines changed

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

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

3-
import androidx.compose.foundation.background
3+
import androidx.compose.foundation.layout.Box
44
import androidx.compose.foundation.layout.padding
55
import androidx.compose.material.Text
66
import androidx.compose.runtime.Composable
@@ -12,9 +12,9 @@ import androidx.compose.runtime.mutableStateMapOf
1212
import androidx.compose.runtime.mutableStateOf
1313
import androidx.compose.runtime.remember
1414
import androidx.compose.runtime.setValue
15+
import androidx.compose.ui.Alignment
1516
import androidx.compose.ui.Modifier
1617
import androidx.compose.ui.geometry.Offset
17-
import androidx.compose.ui.graphics.Color
1818
import androidx.compose.ui.unit.dp
1919
import androidx.compose.ui.unit.sp
2020
import com.squareup.moshi.JsonAdapter
@@ -24,6 +24,11 @@ import com.squareup.workflow1.traceviewer.model.NodeUpdate
2424
import com.squareup.workflow1.traceviewer.ui.DrawTree
2525
import com.squareup.workflow1.traceviewer.util.streamRenderPassesFromDevice
2626

27+
private const val ERROR_MESSAGE =
28+
"\nEnsure app on device is logged in and running before connecting." +
29+
"\n\nNote: Only one live connection per session is currently supported, " +
30+
"\nif you have previously connected restart app on device and try again."
31+
2732
/**
2833
* Handles parsing the trace's after JsonParser has turned all render passes into frames. Also calls
2934
* the UI composables to render the full trace.
@@ -39,7 +44,6 @@ internal fun RenderTrace(
3944
onNewFrame: () -> Unit,
4045
onNewData: (String) -> Unit,
4146
storeNodeLocation: (Node, Offset) -> Unit,
42-
modifier: Modifier = Modifier
4347
) {
4448
key(traceSource) {
4549
var isLoading by remember { mutableStateOf(true) }
@@ -106,7 +110,7 @@ internal fun RenderTrace(
106110
val parseResult = parseLiveTrace(rawRenderPass, adapter, currentTree)
107111
handleParseResult(parseResult, rawRenderPass, onNewFrame)
108112
}
109-
error = "Socket has already been closed or is not available."
113+
error = ERROR_MESSAGE
110114
}
111115
}
112116
}
@@ -115,15 +119,15 @@ internal fun RenderTrace(
115119
// the lambda call to parse the data was immediately cancelled, meaning handleParseResult was never
116120
// called to set isLoading to false.
117121
if (isLoading && error != null) {
118-
Text("Socket Error: $error")
122+
Error("Device Connection Failed:\n$error")
119123
return
120124
}
121125

122126
// This meant that there was an exception, but it was stored in ParseResult and read in
123127
// handleParseResult method. Since there is no parsed data, this likely means there was a moshi
124128
// parsing error.
125129
if (error != null && frames.isEmpty()) {
126-
Text("Malformed File: $error")
130+
Error("Malformed File:\n$error")
127131
return
128132
}
129133

@@ -140,13 +144,18 @@ internal fun RenderTrace(
140144

141145
// This error happens when there has already been previous data parsed, but some exception bubbled
142146
// up again, meaning it has to be a socket closure in Live mode.
143-
error?.let {
144-
Text(
145-
text = "Socket closed: $error",
146-
fontSize = 20.sp,
147-
modifier = modifier.background(Color.White).padding(20.dp)
148-
)
149-
}
147+
error?.let { Error("Lost Connection:\n$error") }
150148
}
151149
}
152150
}
151+
152+
@Composable
153+
fun Error(message: String) {
154+
Box {
155+
Text(
156+
text = message,
157+
fontSize = 20.sp,
158+
modifier = Modifier.align(Alignment.Center).padding(200.dp)
159+
)
160+
}
161+
}

0 commit comments

Comments
 (0)