Skip to content

Commit

Permalink
fix: use ValidationError to determine if an SB1File error should throw
Browse files Browse the repository at this point in the history
  • Loading branch information
mzgoddard committed Dec 20, 2018
1 parent f43163f commit a92f339
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 7 additions & 4 deletions src/virtual-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit a92f339

Please sign in to comment.