createResource swallows error?

I noticed errors get swallowed when I use createResource. Here is some simplified example code:
window.addEventListener('unhandledrejection', (e) => console.error(e));
window.addEventListener('error', (e) => console.error(e));

function getCurrentUserResource() {
const [userData] =
createResource<any>(
async () => {
console.log('hello!') // logs
throw 'error'; // swallowed
}
);
return userData;
}

getCurrentUserResource();
window.addEventListener('unhandledrejection', (e) => console.error(e));
window.addEventListener('error', (e) => console.error(e));

function getCurrentUserResource() {
const [userData] =
createResource<any>(
async () => {
console.log('hello!') // logs
throw 'error'; // swallowed
}
);
return userData;
}

getCurrentUserResource();
The error is not logged in the console
9 Replies
lxsmnsyc
lxsmnsyc2y ago
it is caught by the nearest error boundary
Mathieu
MathieuOP2y ago
I attached those event listeners before the call:
window.addEventListener('unhandledrejection', (e) => handleErrorEvent(e));
window.addEventListener('error', (e) => handleErrorEvent(e));
window.addEventListener('unhandledrejection', (e) => handleErrorEvent(e));
window.addEventListener('error', (e) => handleErrorEvent(e));
If the promise rejection is unhandled, it should call 'unhandledrejection' afaik but it doesn't.
lxsmnsyc
lxsmnsyc2y ago
no I meant literally an ErrorBoundary
Mathieu
MathieuOP2y ago
actually the app didnt render yet at this place hm. but why would that matter @lxsmnsyc in any case I dont see why the error would be swallowed if I have the 'unhandledrejection' handler.
lxsmnsyc
lxsmnsyc2y ago
well you didn't say where the createResource was constructed 🤷‍♂️
Mathieu
MathieuOP2y ago
but does it matter as long as I have a 'unhandledrejection' handler?
high1
high12y ago
createResource handles errors itself
high1
high12y ago
high1
high12y ago
the signal will have error set on error 😄 resource return
Want results from more Discord servers?
Add your server