-
I am working to port Tom Larkworthy's Detect notebook runtime errors with catchAll((cellName, reason) => {...}) to Observable Framework. I think I adjusted the bits necessary for Framework, and I am not seeing any errors—except that now some cells that I attempt to show using The main changes that I made from the original notebook were these: For the mutable bit, I ensured that the Mutable definition and its setter function are included in a single code block: const errorLog = Mutable([]);
const catchAll = (handler, invalidation) => {
const listener = () => handler("unknown", error.value);
error.addEventListener("input", listener);
if (invalidation)
invalidation.then(() => {
error.removeEventListener(listener);
});
}
// update the mutable using .value
catchAll((cellName, reason) => {
let errorLog = errorLog.concat({
cellName,
reason
});
}, invalidation) The notebook error function was written as a view, so I re-fashioned it to use Generators.input: ```js echo
const errorElement = (() => {
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;
})();
let error = Generators.input(errorElement) With these changes in place, however, my cells that attempt to display the ![]() ... I see that there is a spinning arrow icon suggests that I have an unresolved promise or async that I need to handle? I tried using 'await' but it makes no different. Any insights into what is happening and/or suggestions for changes to make this work correctly? 🙏 Code is here: https://github.com/aaronkyle/categorise/blob/master/src/catch-all.md Temporarily available here as a rendered page: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I think I was incorrectly trying to use a generator where it didn't fit, and that seemed to prevent I tried using Here was the original element:
I've revised the code to be closer in line with the original and just excluding the view. My Anywhere in particular I should be looking? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
I think I am getting closer.... though I don't understand all of this. Here's where I am at (corrections and clarifications welcome):
My initial 'loss' of
display()
andview()
outputs was the result of an incorrect attempt to useGenerators.input()
to wire up a reactive input. By using the generator, these cells were never resolving—hence looking like blank or 'missing' values:I can still use the Generator if I correctly wire it up with a different input using bind (though probably this isn't necessary, as just binding the input works without it):
I need to use this combination of defining my input separately from
view()
and then binding to it because later in the notebook I need to use…