Skip to content

Commit

Permalink
Fix message handler on ScriptRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
caponetto committed Sep 18, 2024
1 parent 86401d0 commit a55917e
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions packages/script-editor/src/ScriptRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ import {
Session,
SessionManager
} from '@jupyterlab/services';
import {
IDisplayDataMsg,
IErrorMsg,
IExecuteResultMsg,
IIOPubMessage,
IStatusMsg,
IStreamMsg
} from '@jupyterlab/services/lib/kernel/messages';

const KERNEL_ERROR_MSG =
'Could not run script because no supporting kernel is defined.';
Expand Down Expand Up @@ -93,28 +101,29 @@ export class ScriptRunner {

const future = this.sessionConnection.kernel.requestExecute({ code });

future.onIOPub = (msg: any): void => {
future.onIOPub = (msg: IIOPubMessage): void => {
const msgType = msg.header.msg_type;
const msgOutput: any = {};

if (msg.msg_type === 'error') {
if (msgType === 'error') {
const errorMsg = msg as IErrorMsg;
msgOutput.error = {
type: msg.content.ename,
output: msg.content.evalue
type: errorMsg.content.ename,
output: errorMsg.content.evalue
};
} else if (
msg.msg_type === 'execute_result' ||
msg.msg_type === 'display_data'
) {
if ('text/plain' in msg.content.data) {
msgOutput.output = msg.content.data['text/plain'];
} else if (msgType === 'execute_result' || msgType === 'display_data') {
const resultMsg = msg as IExecuteResultMsg | IDisplayDataMsg;
if ('text/plain' in resultMsg.content.data) {
msgOutput.output = resultMsg.content.data['text/plain'];
} else {
// ignore
console.log('Ignoring received message ' + msg);
console.log('Ignoring received message ' + JSON.stringify(msg));
}
} else if (msg.msg_type === 'stream') {
msgOutput.output = msg.content.text;
} else if (msg.msg_type === 'status') {
msgOutput.status = msg.content.execution_state;
} else if (msgType === 'stream') {
const streamMsg = msg as IStreamMsg;
msgOutput.output = streamMsg.content.text;
} else if (msgType === 'status') {
const statusMsg = msg as IStatusMsg;
msgOutput.status = statusMsg.content.execution_state;
} else {
// ignore other message types
}
Expand Down

0 comments on commit a55917e

Please sign in to comment.