-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…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
- Loading branch information
1 parent
57d5f95
commit c4fbd85
Showing
8 changed files
with
94 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/** | ||
* The list of error codes used in runtime code of the `common` package. | ||
* Reserved error code range: 2000-2999. | ||
*/ | ||
export const enum RuntimeErrorCode { | ||
// NgSwitch errors | ||
PARENT_NG_SWITCH_NOT_FOUND = 2000, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {RuntimeError, RuntimeErrorCode} from '../src/render3/error_code'; | ||
|
||
describe('RuntimeError utils', () => { | ||
it('should format the error message correctly', () => { | ||
// Error with a guide, but without an error message. | ||
let errorInstance = new RuntimeError(RuntimeErrorCode.EXPORT_NOT_FOUND, ''); | ||
expect(errorInstance.toString()) | ||
.toBe('Error: NG0301. Find more at https://angular.io/errors/NG0301'); | ||
|
||
// Error without a guide and an error message. | ||
errorInstance = new RuntimeError(RuntimeErrorCode.TEMPLATE_STRUCTURE_ERROR, ''); | ||
expect(errorInstance.toString()).toBe('Error: NG0305'); | ||
|
||
// Error without a guide, but with an error message. | ||
errorInstance = | ||
new RuntimeError(RuntimeErrorCode.TEMPLATE_STRUCTURE_ERROR, 'Some error message'); | ||
expect(errorInstance.toString()).toBe('Error: NG0305: Some error message'); | ||
|
||
// Error with both a guide and an error message. | ||
errorInstance = new RuntimeError(RuntimeErrorCode.EXPORT_NOT_FOUND, 'Some error message'); | ||
expect(errorInstance.toString()) | ||
.toBe('Error: NG0301: Some error message. Find more at https://angular.io/errors/NG0301'); | ||
}); | ||
}); |