Skip to content

Commit

Permalink
When we try to get blocks from xml headless (without the DOM loaded),…
Browse files Browse the repository at this point in the history
… it should not fail the check
  • Loading branch information
SebastienTainon committed Apr 24, 2024
1 parent 8ecf8d7 commit 698ab5b
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions frontend/stepper/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,14 @@ export const checkBlocklyCode = function (answer: Document, context: QuickAlgoLi
return;
}

const blocks = getBlocksFromXml(blockly);
let blocks;
try {
// This method can fail if Blockly is not loaded in the DOM. In this case it's ok we don't make the check
blocks = getBlocksFromXml(blockly);
} catch (e) {
console.error(e);
return;
}

const maxInstructions = context.infos.maxInstructions ? context.infos.maxInstructions : Infinity;
const totalCount = blocklyCount(blocks, context);
Expand Down Expand Up @@ -274,7 +281,18 @@ export const getBlocklyBlocksUsage = function (answer: Document, context: QuickA

log.getLogger('blockly_runner').debug('blocks usage', answer);

const blocks = getBlocksFromXml(blockly);
let blocks;
try {
// This method can fail if Blockly is not loaded in the DOM. In this case it's ok we don't make the check
blocks = getBlocksFromXml(blockly);
} catch (e) {
console.error(e);
return {
blocksCurrent: 0,
limitations: [],
};
}

const blocksUsed = blocklyCount(blocks, context);
const limitations = (context.infos.limitedUses ? blocklyFindLimited(blocks, context.infos.limitedUses, context) : []) as {type: string, name: string, current: number, limit: number}[];

Expand Down

0 comments on commit 698ab5b

Please sign in to comment.