Published
Edited
Jul 19, 2022
Importers
6 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
errorCell = {
errorTrigger;
// Errors thrown here are picked up by catchAll
throw new Error("An error " + Math.random().toString(16).substring(3));
}
Insert cell
catchAll((cellName, reason) => {
mutable errorLog = mutable errorLog.concat({
cellName,
reason
});
}, invalidation)
Insert cell
Insert cell
Insert cell
viewof error = {
const view = Inputs.input();

const notify = (event) => {
view.value = event.detail.error;
view.dispatchEvent(new Event("input", { bubbles: true }));
};

const processInspectorNode = (el) => {
el.addEventListener("error", notify);
};

// Attach to current cells
[...document.querySelectorAll(".observablehq").values()].forEach(
processInspectorNode
);
// Watch for new cells
const root = document.querySelector(".observablehq-root");
if (root) {
const observer = new MutationObserver((mutationList, observer) => {
for (const mutation of mutationList) {
[...mutation.addedNodes].forEach(processInspectorNode);
}
});
observer.observe(root, {
childList: true
});
invalidation.then(observer.disconnect);
}
return view;
}
Insert cell
catchAll = (handler, invalidation) => {
const listener = () => handler("unknown", viewof error.value);
viewof error.addEventListener("input", listener);
if (invalidation)
invalidation.then(() => {
viewof error.removeEventListener(listener);
});
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more