Skip to content

Commit db92ec9

Browse files
yurydelendikjasonLaster
authored andcommitted
Fixes loading error (firefox-devtools#5090)
1 parent de5fd60 commit db92ec9

7 files changed

Lines changed: 103 additions & 17 deletions

File tree

assets/panel/debugger.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,10 @@ pauseOnExceptions=Pause on all exceptions. Click to ignore exceptions
581581
# yet.
582582
loadingText=Loading\u2026
583583

584+
# LOCALIZATION NOTE (wasmIsNotAvailable): The text that is displayed in the
585+
# script editor when the WebAssembly source is not available.
586+
wasmIsNotAvailable=Please refresh to debug this module
587+
584588
# LOCALIZATION NOTE (errorLoadingText3): The text that is displayed in the debugger
585589
# viewer when there is an error loading a file
586590
errorLoadingText3=Error loading this URI: %S

src/actions/sources/loadSourceText.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,17 @@ export function loadSourceText(source: SourceRecord) {
8181
}
8282

8383
requests.set(id, deferred.promise);
84-
await dispatch({
85-
type: "LOAD_SOURCE_TEXT",
86-
sourceId: id,
87-
[PROMISE]: loadSource(source, { sourceMaps, client })
88-
});
84+
try {
85+
await dispatch({
86+
type: "LOAD_SOURCE_TEXT",
87+
sourceId: id,
88+
[PROMISE]: loadSource(source, { sourceMaps, client })
89+
});
90+
} catch (e) {
91+
deferred.resolve();
92+
requests.delete(id);
93+
return;
94+
}
8995

9096
const newSource = getSource(getState(), source.get("id")).toJS();
9197

src/actions/sources/tests/loadSource.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ describe("loadSourceText", async () => {
116116
it("should indicate an errored source text", async () => {
117117
const { dispatch, getState } = createStore(sourceThreadClient);
118118

119-
await dispatch(actions.loadSourceText(I.Map({ id: "bad-id" }))).catch(
120-
() => {}
121-
);
119+
await dispatch(actions.loadSourceText(I.Map({ id: "bad-id" })));
122120
const badSource = selectors.getSource(getState(), "bad-id");
123121
expect(badSource.get("error").indexOf("unknown source")).not.toBe(-1);
124122
});

src/components/Editor/index.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ import {
4646
showSourceText,
4747
updateDocument,
4848
showLoading,
49+
showErrorMessage,
4950
shouldShowFooter,
5051
createEditor,
52+
clearEditor,
5153
getCursorLine,
5254
toSourceLine,
5355
scrollToColumn,
5456
toEditorPosition,
55-
resetLineNumberFormat,
5657
getSourceLocationFromMouseEvent
5758
} from "../../utils/editor";
5859

@@ -442,28 +443,37 @@ class Editor extends PureComponent<Props, State> {
442443
}
443444

444445
if (!selectedSource) {
445-
return this.showMessage("");
446+
return this.clearEditor();
446447
}
447448

448449
if (!isLoaded(selectedSource)) {
449450
return showLoading(this.state.editor);
450451
}
451452

452453
if (selectedSource.get("error")) {
453-
return this.showMessage(selectedSource.get("error"));
454+
return this.showErrorMessage(selectedSource.get("error"));
454455
}
455456
if (selectedSource) {
456457
return showSourceText(this.state.editor, selectedSource.toJS(), symbols);
457458
}
458459
}
459460

460-
showMessage(msg) {
461+
clearEditor() {
461462
const { editor } = this.state;
462463
if (!editor) {
463464
return;
464465
}
465466

466-
resetLineNumberFormat(editor);
467+
clearEditor(editor);
468+
}
469+
470+
showErrorMessage(msg) {
471+
const { editor } = this.state;
472+
if (!editor) {
473+
return;
474+
}
475+
476+
showErrorMessage(editor, msg);
467477
}
468478

469479
getInlineEditorStyles() {

src/components/Editor/tests/Editor.spec.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe("Editor", () => {
7070
selectedSource: I.fromJS({ loadedState: "loading" })
7171
});
7272

73-
expect(mockEditor.setText.mock.calls).toEqual([["Loading…"]]);
73+
expect(mockEditor.setText.mock.calls).toEqual([[""], ["Loading…"]]);
7474
expect(mockEditor.codeMirror.scrollTo.mock.calls).toEqual([]);
7575
});
7676
});
@@ -86,11 +86,54 @@ describe("Editor", () => {
8686
selectedLocation: { sourceId: "foo", line: 3, column: 1 }
8787
});
8888

89-
expect(mockEditor.setText.mock.calls).toEqual([["the text"]]);
89+
expect(mockEditor.setText.mock.calls).toEqual([[""], ["the text"]]);
9090
expect(mockEditor.codeMirror.scrollTo.mock.calls).toEqual([[1, 2]]);
9191
});
9292
});
9393

94+
describe("When error", () => {
95+
it("should show error text", async () => {
96+
const { component, mockEditor, props } = render({});
97+
98+
await component.setState({ editor: mockEditor });
99+
await component.setProps({
100+
...props,
101+
selectedSource: createMockSource({
102+
loadedState: "loaded",
103+
text: undefined,
104+
error: "error text"
105+
}),
106+
selectedLocation: { sourceId: "bad-foo", line: 3, column: 1 }
107+
});
108+
109+
expect(mockEditor.setText.mock.calls).toEqual([
110+
[""],
111+
["Error loading this URI: error text"]
112+
]);
113+
});
114+
115+
it("should show wasm error", async () => {
116+
const { component, mockEditor, props } = render({});
117+
118+
await component.setState({ editor: mockEditor });
119+
await component.setProps({
120+
...props,
121+
selectedSource: createMockSource({
122+
loadedState: "loaded",
123+
isWasm: true,
124+
text: undefined,
125+
error: "blah WebAssembly binary source is not available blah"
126+
}),
127+
selectedLocation: { sourceId: "bad-foo", line: 3, column: 1 }
128+
});
129+
130+
expect(mockEditor.setText.mock.calls).toEqual([
131+
[""],
132+
["Please refresh to debug this module"]
133+
]);
134+
});
135+
});
136+
94137
describe("When navigating to a loading source", () => {
95138
it("should show loading message and not scroll", async () => {
96139
const { component, mockEditor, props } = render({});
@@ -113,6 +156,7 @@ describe("Editor", () => {
113156
});
114157

115158
expect(mockEditor.setText.mock.calls).toEqual([
159+
[""],
116160
["the text"],
117161
["Loading…"]
118162
]);
@@ -142,6 +186,7 @@ describe("Editor", () => {
142186
});
143187

144188
expect(mockEditor.setText.mock.calls).toEqual([
189+
[""],
145190
["Loading…"],
146191
["the text"]
147192
]);

src/utils/editor/source-documents.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ function updateDocument(editor: SourceEditor, source: SourceRecord) {
6464
updateLineNumberFormat(editor, sourceId);
6565
}
6666

67+
function clearEditor(editor: SourceEditor) {
68+
const doc = editor.createDocument();
69+
editor.replaceDocument(doc);
70+
editor.setText("");
71+
editor.setMode({ name: "text" });
72+
resetLineNumberFormat(editor);
73+
}
74+
6775
function showLoading(editor: SourceEditor) {
6876
if (hasDocument("loading")) {
6977
return;
@@ -76,6 +84,20 @@ function showLoading(editor: SourceEditor) {
7684
editor.setMode({ name: "text" });
7785
}
7886

87+
function showErrorMessage(editor: Object, msg: string) {
88+
let error;
89+
if (msg.includes("WebAssembly binary source is not available")) {
90+
error = L10N.getStr("wasmIsNotAvailable");
91+
} else {
92+
error = L10N.getFormatStr("errorLoadingText3", msg);
93+
}
94+
const doc = editor.createDocument();
95+
editor.replaceDocument(doc);
96+
editor.setText(error);
97+
editor.setMode({ name: "text" });
98+
resetLineNumberFormat(editor);
99+
}
100+
79101
function setEditorText(editor: Object, source: Source) {
80102
const { text, id: sourceId } = source;
81103
if (source.isWasm) {
@@ -129,9 +151,10 @@ export {
129151
hasDocument,
130152
removeDocument,
131153
clearDocuments,
132-
resetLineNumberFormat,
133154
updateLineNumberFormat,
134155
updateDocument,
156+
clearEditor,
135157
showSourceText,
158+
showErrorMessage,
136159
showLoading
137160
};

src/utils/source.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export function getSourcePath(url: string) {
203203
* the function returns amount of bytes.
204204
*/
205205
export function getSourceLineCount(source: Source) {
206-
if (source.isWasm) {
206+
if (source.isWasm && !source.error) {
207207
const { binary } = (source.text: any);
208208
return binary.length;
209209
}

0 commit comments

Comments
 (0)