fix: use ValidationError to determine if an SB1File error should throw

This commit is contained in:
Michael "Z" Goddard 2018-12-19 20:32:35 -05:00
parent f43163fc73
commit a92f33960f
No known key found for this signature in database
GPG key ID: 762CD40DD5349872
3 changed files with 17 additions and 5 deletions

9
package-lock.json generated
View file

@ -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",

View file

@ -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",

View file

@ -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);
}