Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(store): add setting that allows disabling dual error handling #1971

Closed
wants to merge 1 commit into from

Conversation

arturovt
Copy link
Member

@arturovt arturovt commented Mar 1, 2023

Issue: #1965

NGXS has had an explicit error-handling mechanism from actions for the last years. However, this caused issues with ErrorHandler being called twice with the same error. The explicit error handling mechanism is required because of the NGXS action handling strategy. The default action handling process leaves the Angular zone, so NGXS actions are invoked in the <root> zone context. All caught actions must be returned to the Angular error handler.

Angular's default error-handling mechanism requires zone.js to be bundled. The forked Angular zone has an onHandleError hook which calls zone.onError.emit(error) when any error is being caught in Angular zone. Angular subscribes to onError when calls bootstrapModuleFactory:

const exceptionHandler = moduleRef.injector.get(ErrorHandler, null);

...

const subscription = ngZone.onError.subscribe({
    next: (error) => {
        exceptionHandler.handleError(error);
    }
});

This PR adds "switchers" between explicit and implicit error-handling mechanisms. We either catch them manually and delegate them to handleError or allow Angular to catch errors in its zone and delegate them to handleError.

We would use the old behavior where we catch errors explicitly to be backward-compatible and allow users to switch to the implicit behavior where zone.js is responsible for catching errors and delegating them to Angular.

@arturovt arturovt force-pushed the fix/1965 branch 4 times, most recently from e07aa28 to 5ea35e0 Compare March 20, 2023 18:20
@arturovt arturovt marked this pull request as ready for review March 20, 2023 18:21
docs/advanced/errors.md Outdated Show resolved Hide resolved
Copy link
Member

@markwhitfeld markwhitfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this is a great addition, but I'm unsure about the name.
What other names have you thought about?

@ngxs ngxs deleted a comment from codeclimate bot Mar 21, 2023
@markwhitfeld
Copy link
Member

markwhitfeld commented Mar 21, 2023

@arturovt could you describe the two different modes?
The PR description gives a great overview and it describes the two modes as explicit and implicit error handling but the exact difference is unclear.

Could you summarize each mode with details of behavior under each mode?

This will go a long way to help with naming.

@markwhitfeld
Copy link
Member

Upon reviewing this, is suspect that there may actually be a fix that allows this to work as expected in all cases.
I think that there is a bug as I suspected in this comment: https://github.com/ngxs/store/pull/1927/files#r1018904814
The other bug as mentioned here (where the error is reported async):
#1965 (comment)

could be to do with the Promise.resolve().then(... found here:
https://github.com/ngxs/store/pull/1927/files#diff-d211bce5ab62868a141a2954aeb1c7a4f3d3cf03dd08a8ef4f1c8496e1548f0dR32

Do you remember the motivation for this new microtask?

@ngxs ngxs deleted a comment from bundlemon bot Jul 13, 2023
@ngxs ngxs deleted a comment from bundlemon bot Jul 13, 2023
@ngxs ngxs deleted a comment from bundlemon bot Jul 13, 2023
@bundlemon
Copy link

bundlemon bot commented Jul 13, 2023

BundleMon

Files updated (1)
Status Path Size Limits
fesm2015/ngxs-store.js
96.12KB (+1.65KB +1.75%) 125KB / +0.5%
Unchanged files (2)
Status Path Size Limits
fesm2015/ngxs-store-operators.js
6.23KB 15KB / +0.5%
fesm2015/ngxs-store-internals.js
3.57KB 20KB / +0.5%

Total files change +1.65KB +1.58%

Groups updated (3)
Status Path Size Limits
@ngxs/store(esm2015)[gzip]
./esm2015/**/*.js
181.94KB (+1.67KB +0.93%) +1%
@ngxs/store(umd)[gzip]
./bundles/*.umd.js
37.02KB (+485B +1.3%) +1%
@ngxs/store(fesm2015)[gzip]
./fesm2015/*.js
25.41KB (+399B +1.56%) +1%

Final result: ❌

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@bundlemon
Copy link

bundlemon bot commented Jul 13, 2023

BundleMon (NGXS Plugins)

Unchanged files (14)
Status Path Size Limits
Plugins(umd)[gzip]
storage-plugin/bundles/ngxs-storage-plugin.um
d.js
7.94KB +1%
Plugins(umd)[gzip]
router-plugin/bundles/ngxs-router-plugin.umd.
js
7.41KB +1%
Plugins(umd)[gzip]
websocket-plugin/bundles/ngxs-websocket-plugi
n.umd.js
6.92KB +1%
Plugins(umd)[gzip]
hmr-plugin/bundles/ngxs-hmr-plugin.umd.js
6.89KB +1%
Plugins(fesm2015)[gzip]
storage-plugin/fesm2015/ngxs-storage-plugin.j
s
3.67KB +1%
Plugins(umd)[gzip]
form-plugin/bundles/ngxs-form-plugin.umd.js
3.44KB +1%
Plugins(fesm2015)[gzip]
router-plugin/fesm2015/ngxs-router-plugin.js
3.09KB +1%
Plugins(umd)[gzip]
devtools-plugin/bundles/ngxs-devtools-plugin.
umd.js
2.75KB +1%
Plugins(fesm2015)[gzip]
form-plugin/fesm2015/ngxs-form-plugin.js
2.67KB +1%
Plugins(fesm2015)[gzip]
hmr-plugin/fesm2015/ngxs-hmr-plugin.js
2.65KB +1%
Plugins(fesm2015)[gzip]
websocket-plugin/fesm2015/ngxs-websocket-plug
in.js
2.59KB +1%
Plugins(umd)[gzip]
logger-plugin/bundles/ngxs-logger-plugin.umd.
js
2.53KB +1%
Plugins(fesm2015)[gzip]
devtools-plugin/fesm2015/ngxs-devtools-plugin
.js
2.17KB +1%
Plugins(fesm2015)[gzip]
logger-plugin/fesm2015/ngxs-logger-plugin.js
2.01KB +1%

No change in files bundle size

Unchanged groups (3)
Status Path Size Limits
All Plugins(esm2015)[gzip]
./-plugin/esm2015/**/.js
108.83KB +1%
All Plugins(umd)[gzip]
./-plugin/bundles/.umd.js
37.89KB +1%
All Plugins(fesm2015)[gzip]
./-plugin/fesm2015/.js
18.85KB +1%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@nx-cloud
Copy link

nx-cloud bot commented Jul 13, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 4a913cf. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 3 targets

Sent with 💌 from NxCloud.

@ngxs ngxs deleted a comment from bundlemon bot Jul 13, 2023
@arturovt arturovt changed the title fix(store): add flag that allows using new error handling mechanism fix(store): add setting that allows disabling dual error handling Jul 13, 2023
@bundlemon
Copy link

bundlemon bot commented Jul 13, 2023

BundleMon (Integration Projects)

Files updated (2)
Status Path Size Limits
Main bundles(Gzip)
hello-world-ng17/dist-integration/main.(hash)
.js
67.44KB (+41B +0.06%) +1%
Main bundles(Gzip)
hello-world-ng16/dist-integration/main.(hash)
.js
65.94KB (+39B +0.06%) +1%

Total files change +80B +0.06%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@arturovt arturovt force-pushed the fix/1965 branch 2 times, most recently from 8fd2b17 to 4a913cf Compare July 13, 2023 21:18
Copy link

nx-cloud bot commented Feb 16, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit a070882. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 3 targets

Sent with 💌 from NxCloud.

Copy link

codeclimate bot commented Feb 16, 2024

Code Climate has analyzed commit a070882 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 95.5% (0.0% change).

View more on Code Climate.

@arturovt arturovt closed this Mar 21, 2024
@arturovt arturovt deleted the fix/1965 branch March 21, 2024 14:43
@markwhitfeld
Copy link
Member

I had a discussion with @arturovt and we closed this PR in favour of another approach that will be taken in an upcoming PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants