From a92f33960f0e4ce06dd06825916c1315a5972cb3 Mon Sep 17 00:00:00 2001 From: "Michael \"Z\" Goddard" Date: Wed, 19 Dec 2018 20:32:35 -0500 Subject: [PATCH] fix: use ValidationError to determine if an SB1File error should throw --- package-lock.json | 9 +++++++++ package.json | 2 +- src/virtual-machine.js | 11 +++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index b6174c4a..a527bc81 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12204,6 +12204,15 @@ "base64-loader": "1.0.0" } }, + "scratch-sb1-converter": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/scratch-sb1-converter/-/scratch-sb1-converter-0.2.1.tgz", + "integrity": "sha512-Elk3/kVwPEoOGde/4/zvtoSj1tWV/S08qHY+DqhH73JLRjKquw8gvG33BJ5RFnQ/mxgquUlLApr+NjUzNg+TdA==", + "requires": { + "minilog": "3.1.0", + "text-encoding": "^0.6.4" + } + }, "scratch-storage": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/scratch-storage/-/scratch-storage-1.1.0.tgz", diff --git a/package.json b/package.json index b471eaee..c73fa85a 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "minilog": "3.1.0", "nets": "3.2.0", "scratch-parser": "4.3.3", - "scratch-sb1-converter": "github:mzgoddard/scratch-sb1-converter#build-to-sb2-", + "scratch-sb1-converter": "0.2.1", "scratch-translate-extension-languages": "0.0.20181205140428", "socket.io-client": "2.0.4", "text-encoding": "0.6.4", diff --git a/src/virtual-machine.js b/src/virtual-machine.js index e745830b..2d96fc30 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -8,7 +8,7 @@ const ExtensionManager = require('./extension-support/extension-manager'); const log = require('./util/log'); const MathUtil = require('./util/math-util'); const Runtime = require('./engine/runtime'); -const {SB1File} = require('scratch-sb1-converter'); +const {SB1File, ValidationError} = require('scratch-sb1-converter'); const sb2 = require('./serialization/sb2'); const sb3 = require('./serialization/sb3'); const StringUtil = require('./util/string-util'); @@ -294,10 +294,13 @@ class VirtualMachine extends EventEmitter { const sb1 = new SB1File(input); const json = sb1.json; json.projectVersion = 2; - console.log(json); return resolve([json, sb1.zip]); } catch (e) { - console.error(e); + if (e instanceof ValidationError) { + // The input does not validate as a Scratch 1 file. + } else { + throw e; + } } // The second argument of false below indicates to the validator that the @@ -442,7 +445,7 @@ class VirtualMachine extends EventEmitter { const runtime = this.runtime; const deserializePromise = function () { - let projectVersion = projectJSON.projectVersion; + const projectVersion = projectJSON.projectVersion; if (projectVersion === 2) { return sb2.deserialize(projectJSON, runtime, false, zip); }