Skip to content
Snippets Groups Projects
Unverified Commit 64c4d37e authored by Michael "Z" Goddard's avatar Michael "Z" Goddard
Browse files

log workspace update errors

Workspace update errors can be partially recovered from. This allows
the gui to "successfully" load on projects that pass vm validation and
loading but throw an error in scratch-blocks. Logging the error instead
of throwing it allows the gui and vm to finish updating for the
workspace change. This allows the VM to behave normally even if the
scratch-blocks workspace rendering is incomplete.
parent e9c776da
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ import VMScratchBlocks from '../lib/blocks'; ...@@ -8,6 +8,7 @@ import VMScratchBlocks from '../lib/blocks';
import VM from 'scratch-vm'; import VM from 'scratch-vm';
import analytics from '../lib/analytics'; import analytics from '../lib/analytics';
import log from '../lib/log.js';
import Prompt from './prompt.jsx'; import Prompt from './prompt.jsx';
import ConnectionModal from './connection-modal.jsx'; import ConnectionModal from './connection-modal.jsx';
import BlocksComponent from '../components/blocks/blocks.jsx'; import BlocksComponent from '../components/blocks/blocks.jsx';
...@@ -300,7 +301,21 @@ class Blocks extends React.Component { ...@@ -300,7 +301,21 @@ class Blocks extends React.Component {
// Remove and reattach the workspace listener (but allow flyout events) // Remove and reattach the workspace listener (but allow flyout events)
this.workspace.removeChangeListener(this.props.vm.blockListener); this.workspace.removeChangeListener(this.props.vm.blockListener);
const dom = this.ScratchBlocks.Xml.textToDom(data.xml); const dom = this.ScratchBlocks.Xml.textToDom(data.xml);
this.ScratchBlocks.Xml.clearWorkspaceAndLoadFromXml(dom, this.workspace); try {
this.ScratchBlocks.Xml.clearWorkspaceAndLoadFromXml(dom, this.workspace);
} catch (error) {
// The workspace is likely incomplete. What did update should be
// functional.
//
// Instead of throwing the error, by logging it and continuing as
// normal lets the other workspace update processes complete in the
// gui and vm, which lets the vm run even if the workspace is
// incomplete. Throwing the error would keep things like setting the
// correct editing target from happening which can interfere with
// some blocks and processes in the vm.
error.message = `Workspace Update Error: ${error.message}`;
log.error(error);
}
this.workspace.addChangeListener(this.props.vm.blockListener); this.workspace.addChangeListener(this.props.vm.blockListener);
if (this.props.vm.editingTarget && this.state.workspaceMetrics[this.props.vm.editingTarget.id]) { if (this.props.vm.editingTarget && this.state.workspaceMetrics[this.props.vm.editingTarget.id]) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment