Skip to content

Commit c4f2b7d

Browse files
committed
avoid assertion when querying error source
1 parent 6861caa commit c4f2b7d

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

src/main.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -229,22 +229,27 @@ function main() {
229229
customDictionaryErrorList.innerHTML = "";
230230
for (const error of errors) {
231231
const listItem = document.createElement("li");
232-
const link = document.createElement("a");
233-
listItem.appendChild(link);
234232
customDictionaryErrorList.appendChild(listItem);
235233

236-
link.href = "#";
237-
link.innerText = error.message;
238-
const { position: { position, length } } = error as PositionedError & {
239-
position: Position;
240-
};
241-
link.addEventListener("click", () => {
242-
customDictionaryTextBox.focus();
243-
customDictionaryTextBox.setSelectionRange(
244-
position,
245-
position + length,
246-
);
247-
});
234+
if (error instanceof PositionedError && error.position != null) {
235+
const link = document.createElement("a");
236+
listItem.appendChild(link);
237+
238+
link.href = "#";
239+
link.innerText = error.message;
240+
const { position: { position, length } } = error as PositionedError & {
241+
position: Position;
242+
};
243+
link.addEventListener("click", () => {
244+
customDictionaryTextBox.focus();
245+
customDictionaryTextBox.setSelectionRange(
246+
position,
247+
position + length,
248+
);
249+
});
250+
} else {
251+
listItem.innerText = error.message;
252+
}
248253
}
249254
}
250255
// add all event listener

0 commit comments

Comments
 (0)