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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ngDevMode to tree shake error messages in pipes #40096

Closed
dev054 opened this issue Dec 11, 2020 · 10 comments
Closed

Use ngDevMode to tree shake error messages in pipes #40096

dev054 opened this issue Dec 11, 2020 · 10 comments
Labels
area: common Issues related to APIs in the @angular/common package cross-cutting: tree-shaking feature: in backlog Feature request for which voting has completed and is now in the backlog refactoring Issue that involves refactoring or code-cleanup
Milestone

Comments

@dev054
Copy link

dev054 commented Dec 11, 2020

馃殌 feature request

Description

Currently all the errors throwed by pipes are not being tree-shaked in production mode.

Relevant Package

@angular/common/(pipes)

Example:

if (typeof value !== 'string') {
throw invalidPipeArgumentError(LowerCasePipe, value);
}

Describe the solution you'd like

I have seen that you made a lot of progress with ngDevMode, so I think it would be a case of using it for the purpose of making the package smaller.

@AndrewKushnir AndrewKushnir added area: common Issues related to APIs in the @angular/common package cross-cutting: tree-shaking labels Dec 12, 2020
@ngbot ngbot bot modified the milestone: needsTriage Dec 12, 2020
@AndrewKushnir AndrewKushnir added the feature Issue that requests a new feature label Dec 12, 2020
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Dec 12, 2020
@AndrewKushnir AndrewKushnir added the refactoring Issue that involves refactoring or code-cleanup label Dec 12, 2020
@alan-agius4
Copy link
Contributor

I don鈥檛 think these errors should be removed when not ngDevMode is false.

Data can be non statically analysable such as from an API. In which case invalid value type should result in a meaningful and actionable errors.

Although it does feel weird that we allow undefined as an input just to throw that it鈥檚 an invalid value. Maybe this is for compatibility reasons?

@dev054
Copy link
Author

dev054 commented Dec 12, 2020

I don鈥檛 think these errors should be removed when not ngDevMode is false.

@alan-agius4 Hmm, would you mind to share how do you decide an error message should be thrown in production mode or not? I'm asking it to understand as I saw ngDevMode being used in many places in @angular/router.

Although it does feel weird that we allow undefined as an input just to throw that it鈥檚 an invalid value. Maybe this is for compatibility reasons?

Maybe. I also found it strange (because even the async pipe which could be a problem, doesn't return undefined, but null), and I noticed that it was added in #37447.

@lazarljubenovic
Copy link
Contributor

lazarljubenovic commented Dec 13, 2020

Data can be non statically analysable such as from an API. In which case invalid value type should result in a meaningful and actionable errors.

I thought Ivy now properly checks the type of pipes?

transform(value: string): string;
transform(value: null|undefined): null;
transform(value: string|null|undefined): string|null;
transform(value: string|null|undefined): string|null {

The function will already scream at you during compilation for passing a wrong argument type.

@alan-agius4
Copy link
Contributor

In this particular case undefined is a valid argument type, but when passed it causes a runtime exception.

@alan-agius4
Copy link
Contributor

alan-agius4 commented Dec 13, 2020

Actually never mind, I just noticed that the check in

if (value == null) return null;
is using double = and not triple.

So you are right 馃槉

@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Jun 4, 2021
@angular-robot
Copy link
Contributor

angular-robot bot commented Jun 4, 2021

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

@angular-robot
Copy link
Contributor

angular-robot bot commented Jun 25, 2021

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.

@angular-robot angular-robot bot added the feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors label Jun 25, 2021
@AndrewKushnir
Copy link
Contributor

I think it should be safe to tree-shake away this error in prod mode (in all pipes within the case_conversion_pipes.ts script).

@ramthir this looks similar to other changes you made recently. Please let us know if you might be interested in helping with this code?

@AndrewKushnir AndrewKushnir added feature: in backlog Feature request for which voting has completed and is now in the backlog and removed feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors feature: votes required Feature request which is currently still in the voting phase feature Issue that requests a new feature labels Jan 7, 2022
@ngbot ngbot bot modified the milestones: Backlog, needsTriage Jan 7, 2022
@ramthir
Copy link
Contributor

ramthir commented Jan 7, 2022

I think it should be safe to tree-shake away this error in prod mode (in all pipes within the case_conversion_pipes.ts script).

@ramthir this looks similar to other changes you made recently. Please let us know if you might be interested in helping with this code?

Great @AndrewKushnir, I'll raise a PR on this. 馃憤

dylhunn pushed a commit that referenced this issue Jan 18, 2022
Make Long error messages tree-shakable in the production build with error codes.

fixes #40096

PR Close #44663
@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 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: common Issues related to APIs in the @angular/common package cross-cutting: tree-shaking feature: in backlog Feature request for which voting has completed and is now in the backlog refactoring Issue that involves refactoring or code-cleanup
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants