-
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.
refactor(core): add a new stringifier for runtime errors which includ…
…es debug info such as the file path and line number (#51919) The current error stringifier only includes the class name. In this change a new stringifier is added which returns a more helpful string which includes the file path and line number. Note that this is only the case with components, and for other class types (directive, pipes) it will fallback to the current stringifier. Subsequent changes can cover the case of directive and pipes as well. PR Close #51919
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 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,49 @@ | ||
/** | ||
* @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 {ɵsetClassDebugInfo, ɵɵdefineComponent} from '@angular/core/src/render3'; | ||
import {debugStringifyTypeForError} from '@angular/core/src/render3/util/stringify_utils'; | ||
|
||
describe('stringify utils', () => { | ||
describe('stringifyTypeForError util', () => { | ||
it('should include the file path and line number for component if debug info includes them', | ||
() => { | ||
class Comp { | ||
static ɵcmp = ɵɵdefineComponent({type: Comp, decls: 0, vars: 0, template: () => ''}); | ||
} | ||
ɵsetClassDebugInfo(Comp, { | ||
className: 'Comp', | ||
filePath: 'comp.ts', | ||
lineNumber: 11, | ||
}); | ||
|
||
expect(debugStringifyTypeForError(Comp)).toBe('Comp (at comp.ts:11)'); | ||
}); | ||
|
||
it('should include only the class name if debug info does not contain file path', () => { | ||
class Comp { | ||
static ɵcmp = ɵɵdefineComponent({type: Comp, decls: 0, vars: 0, template: () => ''}); | ||
} | ||
ɵsetClassDebugInfo(Comp, { | ||
className: 'Comp', | ||
lineNumber: 11, | ||
}); | ||
|
||
expect(debugStringifyTypeForError(Comp)).toBe('Comp'); | ||
}); | ||
|
||
it('should default to showing just the class name for component if debug info is not available', | ||
() => { | ||
class Comp { | ||
static ɵcmp = ɵɵdefineComponent({type: Comp, decls: 0, vars: 0, template: () => ''}); | ||
} | ||
|
||
expect(debugStringifyTypeForError(Comp)).toBe('Comp'); | ||
}); | ||
}); | ||
}); |