Handle errors in trace (#8775)

This commit is contained in:
Bram Kragten
2021-03-31 18:35:30 +02:00
committed by GitHub
parent 9b947ef734
commit 9a68bdeec1
4 changed files with 23 additions and 18 deletions

View File

@@ -93,7 +93,7 @@ class HatScriptGraph extends LitElement {
const path = `condition/${i}`;
const trace = this.trace.trace[path] as ConditionTraceStep[] | undefined;
const track_path =
trace === undefined ? 0 : trace![0].result.result ? 1 : 2;
trace?.[0].result === undefined ? 0 : trace[0].result.result ? 1 : 2;
if (trace) {
this.trackedNodes[path] = { config, path };
}
@@ -139,7 +139,7 @@ class HatScriptGraph extends LitElement {
private render_choose_node(config: ChooseAction, path: string) {
const trace = this.trace.trace[path] as ChooseActionTraceStep[] | undefined;
const trace_path = trace
const trace_path = trace?.[0].result
? trace[0].result.choice === "default"
? [config.choose.length]
: [trace[0].result.choice]
@@ -173,7 +173,7 @@ class HatScriptGraph extends LitElement {
.iconPath=${mdiCheckBoxOutline}
nofocus
class=${classMap({
track: trace !== undefined && trace[0].result.choice === i,
track: trace !== undefined && trace[0].result?.choice === i,
})}
></hat-graph-node>
${branch.sequence.map((action, j) =>
@@ -188,7 +188,7 @@ class HatScriptGraph extends LitElement {
nofocus
class=${classMap({
track:
trace !== undefined && trace[0].result.choice === "default",
trace !== undefined && trace[0].result?.choice === "default",
})}
></hat-graph-node>
${config.default?.map((action, i) =>
@@ -200,8 +200,9 @@ class HatScriptGraph extends LitElement {
}
private render_condition_node(node: Condition, path: string) {
const trace: any = this.trace.trace[path];
const track_path = trace === undefined ? 0 : trace[0].result.result ? 1 : 2;
const trace = (this.trace.trace[path] as ConditionTraceStep[]) || undefined;
const track_path =
trace?.[0].result === undefined ? 0 : trace[0].result.result ? 1 : 2;
return html`
<hat-graph
branching
@@ -218,7 +219,7 @@ class HatScriptGraph extends LitElement {
<hat-graph-node
slot="head"
class=${classMap({
track: trace,
track: Boolean(trace),
})}
.iconPath=${mdiAbTesting}
nofocus