show errors while mounting list view children

This commit is contained in:
Bruno Windels 2021-05-31 12:28:42 +02:00
parent 762ed96a3b
commit 2e34668b91
2 changed files with 11 additions and 3 deletions

View File

@ -15,6 +15,7 @@ limitations under the License.
*/
import {tag} from "./html.js";
import {errorToDOM} from "./error.js";
function insertAt(parentNode, idx, childNode) {
const isLast = idx === parentNode.childElementCount;
@ -106,8 +107,12 @@ export class ListView {
for (let item of this._list) {
const child = this._childCreator(item);
this._childInstances.push(child);
const childDomNode = child.mount(this._mountArgs);
fragment.appendChild(childDomNode);
try {
const childDomNode = child.mount(this._mountArgs);
fragment.appendChild(childDomNode);
} catch (err) {
fragment.appendChild(errorToDOM(err));
}
}
this._root.appendChild(fragment);
}

View File

@ -18,7 +18,10 @@ import {tag} from "./html.js";
export function errorToDOM(error) {
const stack = new Error().stack;
const callee = stack.split("\n")[1];
let callee = null;
if (stack) {
callee = stack.split("\n")[1];
}
return tag.div([
tag.h2("Something went wrong…"),
tag.h3(error.message),