Skip to content

Commit dca56cf

Browse files
authored
Merge pull request #3144 from mzgoddard/allow-workspace-loading-error
log workspace update errors
2 parents a924340 + 64c4d37 commit dca56cf

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/containers/blocks.jsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import VMScratchBlocks from '../lib/blocks';
88
import VM from 'scratch-vm';
99

1010
import analytics from '../lib/analytics';
11+
import log from '../lib/log.js';
1112
import Prompt from './prompt.jsx';
1213
import ConnectionModal from './connection-modal.jsx';
1314
import BlocksComponent from '../components/blocks/blocks.jsx';
@@ -300,7 +301,21 @@ class Blocks extends React.Component {
300301
// Remove and reattach the workspace listener (but allow flyout events)
301302
this.workspace.removeChangeListener(this.props.vm.blockListener);
302303
const dom = this.ScratchBlocks.Xml.textToDom(data.xml);
303-
this.ScratchBlocks.Xml.clearWorkspaceAndLoadFromXml(dom, this.workspace);
304+
try {
305+
this.ScratchBlocks.Xml.clearWorkspaceAndLoadFromXml(dom, this.workspace);
306+
} catch (error) {
307+
// The workspace is likely incomplete. What did update should be
308+
// functional.
309+
//
310+
// Instead of throwing the error, by logging it and continuing as
311+
// normal lets the other workspace update processes complete in the
312+
// gui and vm, which lets the vm run even if the workspace is
313+
// incomplete. Throwing the error would keep things like setting the
314+
// correct editing target from happening which can interfere with
315+
// some blocks and processes in the vm.
316+
error.message = `Workspace Update Error: ${error.message}`;
317+
log.error(error);
318+
}
304319
this.workspace.addChangeListener(this.props.vm.blockListener);
305320

306321
if (this.props.vm.editingTarget && this.state.workspaceMetrics[this.props.vm.editingTarget.id]) {

0 commit comments

Comments
 (0)