Fix host event type and reference errors

This commit is contained in:
Jake McDermott
2020-03-23 11:44:03 -04:00
parent 4529429e99
commit fe2ebeb872

View File

@@ -97,7 +97,9 @@ const processCodeMirrorValue = value => {
}; };
const processStdOutValue = hostEvent => { const processStdOutValue = hostEvent => {
const { taskAction, res } = hostEvent.event_data; const taskAction = hostEvent?.event_data?.taskAction;
const res = hostEvent?.event_data?.res;
let stdOut; let stdOut;
if (taskAction === 'debug' && res.result && res.result.stdout) { if (taskAction === 'debug' && res.result && res.result.stdout) {
stdOut = res.result.stdout; stdOut = res.result.stdout;
@@ -107,7 +109,7 @@ const processStdOutValue = hostEvent => {
Array.isArray(res.results) Array.isArray(res.results)
) { ) {
[stdOut] = res.results; [stdOut] = res.results;
} else { } else if (res) {
stdOut = res.stdout; stdOut = res.stdout;
} }
return stdOut; return stdOut;
@@ -125,8 +127,8 @@ function HostEventModal({ onClose, hostEvent = {}, isOpen = false, i18n }) {
setActiveTabKey(tabIndex); setActiveTabKey(tabIndex);
}; };
const jsonObj = processCodeMirrorValue(hostEvent.event_data.res); const jsonObj = processCodeMirrorValue(hostEvent?.event_data?.res);
const stdErr = processCodeMirrorValue(hostEvent.event_data.res.stderr); const stdErr = processCodeMirrorValue(hostEvent?.event_data?.res?.stderr);
const stdOut = processCodeMirrorValue(processStdOutValue(hostEvent)); const stdOut = processCodeMirrorValue(processStdOutValue(hostEvent));
return ( return (
@@ -167,7 +169,7 @@ function HostEventModal({ onClose, hostEvent = {}, isOpen = false, i18n }) {
/> />
<Detail <Detail
label={i18n._(t`Command`)} label={i18n._(t`Command`)}
value={hostEvent.event_data.res.cmd} value={hostEvent?.event_data?.res?.cmd}
/> />
</DetailList> </DetailList>
</Tab> </Tab>