angular: Improve the `The pipe could not be found` error message
Which @angular/* package(s) are relevant/releated to the feature request?
core
Description
Currently Angular throws the following error message at runtime when a pipe can not be found:
The pipe `AsyncPipe` could not be found!
However there is no information on which component has this problem, which makes debugging harder. We should consider adding component class name to the error message.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 11
- Comments: 23 (22 by maintainers)
@rohan-pednekar please see my comment to your PR: https://github.com/angular/angular/pull/44081#discussion_r743914851. Here is the change that should take care of the mentioned issue:
You could target changed files only using this command:
More info can be found at https://github.com/angular/angular/blob/master/docs/DEVELOPER.md#formatting-your-source-code.
@rohan-pednekar I think you should add tests to the
packages/core/test/acceptance/pipe_spec.ts
file only, there is no need to add them to therender3
directory (we would migrate the remaining tests from there to theacceptance
folder eventually). Once the tests are added, you can use the following command to run them:You could also focus a particular suite or a test using
fdescribe
orfit
.Please let me know if that worked.
Thank you.
@rohan-pednekar I’ve looked at the code and here is a possible implementation to get the necessary info and include it into the error message:
The idea is that we get a hold of an internal representation of a component view, where a given pipe was declared (in component’s template) and look at the context (which refers to the component class instance itself). We also do that inside the
if (ngDevMode) { ... }
check, so that we tree-shake away this code from production bundles (so it’s a dev-mode-only code).If you want to put together a PR - feel free to use the code above. The PR should also have sufficient test coverage, including a few important cases (based on the extra logic from the fix):
{{ value | missingPipe }}
<ng-container *ngIf="true">{{ value | missingPipe }}</ng-container>
<my-comp>{{ value | missingPipe }}</my-comp>
<my-comp><ng-container *ngIf="true">{{ value | missingPipe }}</ng-container></my-comp>
<div [title]="value | missingPipe"></div>
<div *ngIf="isVisible | missingPipe"></div>
You can find existing test suites for pipes logic in the
packages/core/test/acceptance/pipe_spec.ts
file.Please let us know if you have any questions.
Thank you.