Skip to content

[13.1.x] refactor: make RuntimeError class reusable across packages#44652

Closed
AndrewKushnir wants to merge 3 commits intoangular:13.1.xfrom
AndrewKushnir:cp_44398
Closed

[13.1.x] refactor: make RuntimeError class reusable across packages#44652
AndrewKushnir wants to merge 3 commits intoangular:13.1.xfrom
AndrewKushnir:cp_44398

Conversation

@AndrewKushnir
Copy link
Contributor

This PR is a patch-only version of #44398 (there was a minor merge conflict).

@AndrewKushnir AndrewKushnir added area: forms target: patch This PR is targeted for the next patch release PullApprove: disable labels Jan 7, 2022
@ngbot ngbot bot modified the milestone: Backlog Jan 7, 2022
…4398)

This commit updates the code around the `RuntimeError` class to make it more reusable between packages (currently it's only usable inside the `core` package). Specifically:
- the error formatting logic was updated to handle cases when there is no error message provided
- there is no special Set that contains a set of error codes for which we have guides on angular.io. Instead, this is now encoded into the error code itself (making such codes negative integers). Having a separate Set makes it non-tree-shakable, which we want to avoid.

This change should allow to employ the `RuntimeError` class in other packages to further standardize this subsystem and make the errors thrown by the framework consistent.

As a part of the refactoring, the `common` package code was also updated to follow the same logic as `core`, since the `RuntimeError` class was used there as well.

PR Close angular#44398
This commit moves some logic to make the location of runtime error codes consistent across packages. Now all error codes are located in `packages/core/src/errors.ts` file.

PR Close angular#44398
This commit performs some refactoring of the AbstractControl-based classes to employ shared `RuntimeError` class and also updates the code to avoid duplication and improve minification.

PR Close angular#44398
@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Jan 7, 2022
@AndrewKushnir
Copy link
Contributor Author

@atscott FYI this is a patch-only version of the PR #44398 that conflicted with the 13.1.x branch. Thank you.

*/
export const enum RuntimeErrorCode {
// Change Detection Errors
EXPRESSION_CHANGED_AFTER_CHECKED = -100,
Copy link
Contributor

Choose a reason for hiding this comment

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

When do we use error codes with negative values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See comment above:

 * Note: the minus sign denotes the fact that a particular code has a detailed guide on
 * angular.io. This extra annotation is needed to avoid introducing a separate set to store
 * error codes which have guides, which might leak into runtime code.

@AndrewKushnir AndrewKushnir marked this pull request as ready for review January 7, 2022 05:52
@atscott
Copy link
Contributor

atscott commented Jan 7, 2022

This PR was merged into the repository by commit d252cff.

@atscott atscott closed this Jan 7, 2022
atscott pushed a commit that referenced this pull request Jan 7, 2022
…44652)

This commit updates the code around the `RuntimeError` class to make it more reusable between packages (currently it's only usable inside the `core` package). Specifically:
- the error formatting logic was updated to handle cases when there is no error message provided
- there is no special Set that contains a set of error codes for which we have guides on angular.io. Instead, this is now encoded into the error code itself (making such codes negative integers). Having a separate Set makes it non-tree-shakable, which we want to avoid.

This change should allow to employ the `RuntimeError` class in other packages to further standardize this subsystem and make the errors thrown by the framework consistent.

As a part of the refactoring, the `common` package code was also updated to follow the same logic as `core`, since the `RuntimeError` class was used there as well.

PR Close #44398

PR Close #44652
atscott pushed a commit that referenced this pull request Jan 7, 2022
This commit moves some logic to make the location of runtime error codes consistent across packages. Now all error codes are located in `packages/core/src/errors.ts` file.

PR Close #44398

PR Close #44652
atscott pushed a commit that referenced this pull request Jan 7, 2022
This commit performs some refactoring of the AbstractControl-based classes to employ shared `RuntimeError` class and also updates the code to avoid duplication and improve minification.

PR Close #44398

PR Close #44652
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: forms merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note PullApprove: disable target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants