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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 18 deletions

View File

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

View File

@ -302,7 +302,7 @@ class ActionRenderer {
const startLevel = choosePath.split("/").length - 1; const startLevel = choosePath.split("/").length - 1;
const chooseTrace = this._getItem(index)[0] as ChooseActionTraceStep; const chooseTrace = this._getItem(index)[0] as ChooseActionTraceStep;
const defaultExecuted = chooseTrace.result.choice === "default"; const defaultExecuted = chooseTrace.result?.choice === "default";
const chooseConfig = this._getDataFromPath( const chooseConfig = this._getDataFromPath(
this.keys[index] this.keys[index]
) as ChooseAction; ) as ChooseAction;
@ -312,11 +312,14 @@ class ActionRenderer {
this._renderEntry(choosePath, `${name}: Default action executed`); this._renderEntry(choosePath, `${name}: Default action executed`);
} else { } else {
const choiceConfig = this._getDataFromPath( const choiceConfig = this._getDataFromPath(
`${this.keys[index]}/choose/${chooseTrace.result.choice}` `${this.keys[index]}/choose/${chooseTrace.result?.choice}`
) as ChooseActionChoice; ) as ChooseActionChoice | undefined;
const choiceName = const choiceName = choiceConfig
choiceConfig.alias || `Choice ${chooseTrace.result.choice}`; ? `${
this._renderEntry(choosePath, `${name}: ${choiceName} executed`); choiceConfig.alias || `Choice ${chooseTrace.result?.choice}`
} executed`
: `Error: ${chooseTrace.error}`;
this._renderEntry(choosePath, `${name}: ${choiceName}`);
} }
let i; let i;

View File

@ -5,6 +5,7 @@ import { AutomationConfig } from "./automation";
interface BaseTraceStep { interface BaseTraceStep {
path: string; path: string;
timestamp: string; timestamp: string;
error?: string;
changed_variables?: Record<string, unknown>; changed_variables?: Record<string, unknown>;
} }
@ -19,11 +20,11 @@ export interface TriggerTraceStep extends BaseTraceStep {
} }
export interface ConditionTraceStep extends BaseTraceStep { export interface ConditionTraceStep extends BaseTraceStep {
result: { result: boolean }; result?: { result: boolean };
} }
export interface CallServiceActionTraceStep extends BaseTraceStep { export interface CallServiceActionTraceStep extends BaseTraceStep {
result: { result?: {
limit: number; limit: number;
running_script: boolean; running_script: boolean;
params: Record<string, unknown>; params: Record<string, unknown>;
@ -36,11 +37,11 @@ export interface CallServiceActionTraceStep extends BaseTraceStep {
} }
export interface ChooseActionTraceStep extends BaseTraceStep { export interface ChooseActionTraceStep extends BaseTraceStep {
result: { choice: number | "default" }; result?: { choice: number | "default" };
} }
export interface ChooseChoiceActionTraceStep extends BaseTraceStep { export interface ChooseChoiceActionTraceStep extends BaseTraceStep {
result: { result: boolean }; result?: { result: boolean };
} }
export type ActionTraceStep = export type ActionTraceStep =

View File

@ -259,7 +259,7 @@ class HaLogbook extends LitElement {
haStyle, haStyle,
haStyleScrollbar, haStyleScrollbar,
css` css`
:host { :host([virtualize]) {
display: block; display: block;
height: 100%; height: 100%;
} }