Skip to content

Commit 734b37f

Browse files
author
Josh Lory
authored
Merge pull request code-dot-org#24791 from code-dot-org/rescue-from-codegen-errors
Defend against null inputConfig when generating code for a block
2 parents a341424 + be0df1b commit 734b37f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

apps/src/block_utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,9 @@ exports.createJsWrapperBlockCreator = function (
878878
let prefix = '';
879879
const values = args.map(arg => {
880880
const inputConfig = inputConfigs.find(input => input.name === arg.name);
881+
if (!inputConfig) {
882+
return;
883+
}
881884
let inputCode = inputTypes[inputConfig.mode].generateCode(this, inputConfig);
882885
if (inputConfig.assignment) {
883886
prefix += `${inputCode} = `;

apps/test/unit/blockUtilsTest.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { parseElement, serialize } from '@cdo/apps/xml.js';
1212
import { expect } from '../util/configuredChai';
1313
import sinon from 'sinon';
14+
import { allowConsoleWarnings } from '../util/testUtils';
1415

1516
describe('block utils', () => {
1617
describe('cleanBlocks', () => {
@@ -955,6 +956,7 @@ describe('block utils', () => {
955956
});
956957
});
957958
describe('custom inputs', () => {
959+
allowConsoleWarnings();
958960
it('generates code for a statement input', () => {
959961
createBlock({
960962
func: 'runThisCallback',
@@ -1061,6 +1063,17 @@ describe('block utils', () => {
10611063
expect(code.trim()).to.equal(
10621064
'processAnotherStringValue("some input with a \\"quote\\" in it");');
10631065
});
1066+
it('does not throw when there are extra args', () => {
1067+
createBlock({
1068+
name: 'extraArgsTest',
1069+
expression: 'extraArgsTest;',
1070+
blockText: 'run this program in strict mode',
1071+
args: [{name: 'EXTRA'}],
1072+
}, '', 'test');
1073+
const code = generator['test_extraArgsTest']();
1074+
1075+
expect(code.trim()).to.equal('extraArgsTest;');
1076+
});
10641077
});
10651078
});
10661079
});

0 commit comments

Comments
 (0)