From 635b40ec2b89e454532924564fe5a0d96d3d814e Mon Sep 17 00:00:00 2001 From: Ray Schamp Date: Thu, 11 May 2017 02:22:12 -0400 Subject: [PATCH] Log parsing errors --- src/virtual-machine.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/virtual-machine.js b/src/virtual-machine.js index f5906958e..fce3244ad 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -191,9 +191,15 @@ class VirtualMachine extends EventEmitter { this.clear(); // Validate & parse - if (typeof json !== 'string') return; + if (typeof json !== 'string') { + log.error('Failed to parse project. Non-string supplied to fromJSON.'); + return; + } json = JSON.parse(json); - if (typeof json !== 'object') return; + if (typeof json !== 'object') { + log.error('Failed to parse project. JSON supplied to fromJSON is not an object.'); + return; + } // Establish version, deserialize, and load into runtime // @todo Support Scratch 1.4 @@ -232,9 +238,15 @@ class VirtualMachine extends EventEmitter { */ addSprite2 (json) { // Validate & parse - if (typeof json !== 'string') return; + if (typeof json !== 'string') { + log.error('Failed to parse sprite. Non-string supplied to addSprite2.'); + return; + } json = JSON.parse(json); - if (typeof json !== 'object') return; + if (typeof json !== 'object') { + log.error('Failed to parse sprite. JSON supplied to addSprite2 is not an object.'); + return; + } // Select new sprite. return sb2.deserialize(json, this.runtime, true).then(targets => {