lwc icon indicating copy to clipboard operation
lwc copied to clipboard

Wire dynamic properties that throw in getter result in unhandledRejection

Open wes-goulet opened this issue 4 years ago • 1 comments

Description

If a component has a wire whose dynamic property throws in a getter then that will result in an unhandledRejection. I would think it should be part of the LWC error boundary (emitted by errorCallback) but it is not.

Steps to Reproduce

export default class GetterThrowsComponent extends LightningElement {
    errorCallback(error, _stack) {
        console.log("this never hits")
    }

    get id() {
        throw new Error('error in getter');
    }

    @wire(wireAdapter, {
        id: '$id',
    })
    onTestEntity(_result) {
    }
}

Expected Results

Since the error originated in the component I would expect errorCallback to emit that error.

Actual Results

errorCallback does not emit the error and the error instead goes to the global unhandledRejection event.

Browsers Affected

Version

  • LWC: 1.7.5

Possible Solution

The problem is in the createConnector function in wiring.ts - there is Promise.then but no catch to handle when computeAndConfigUpdate rejects.

wes-goulet avatar Sep 24 '20 21:09 wes-goulet

Very good point! This would be perfect to have.

I am looking for a solution, how are we able to catch those unhandledRejection errors at the moment. Any idea?

bokiftw avatar Jul 26 '22 08:07 bokiftw