Skip to content

Commit

Permalink
Better code node error when it doesn't return something valid.
Browse files Browse the repository at this point in the history
  • Loading branch information
abrenneke committed Oct 23, 2023
1 parent 617a57c commit 231268c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/core/src/model/nodes/CodeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class CodeNodeImpl extends NodeImpl<CodeNode> {
static getUIData(): NodeUIData {
return {
infoBoxBody: dedent`
Executes a piece of JavaScript code. Documentation for the inputs and outputs is available in the default code.
Executes a piece of JavaScript code. See the Rivet Documentation for more information on how to write code for the Code Node.
`,
infoBoxTitle: 'Code Node',
contextMenuTitle: 'Code',
Expand All @@ -134,6 +134,11 @@ export class CodeNodeImpl extends NodeImpl<CodeNode> {
// eslint-disable-next-line no-new-func
const codeFunction = new Function('inputs', this.chartNode.data.code);
const outputs = codeFunction(inputs);

if (outputs == null || typeof outputs !== 'object') {
throw new Error('Code node must return an object with output values.');
}

return outputs;
}
}
Expand Down

0 comments on commit 231268c

Please sign in to comment.