mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-20 10:19:35 -04:00
fix: use ValidationError to determine if an SB1File error should throw
This commit is contained in:
parent
f43163fc73
commit
a92f33960f
3 changed files with 17 additions and 5 deletions
9
package-lock.json
generated
9
package-lock.json
generated
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue