Skip to content

fix(core): throw error message when @Output not initialized - #19116

Closed
aldo-roman wants to merge 5 commits into
angular:masterfrom
aldo-roman:fix/uninitialized-output-error
Closed

aldo-roman wants to merge 5 commits into
angular:masterfrom
aldo-roman:fix/uninitialized-output-error

Conversation

@aldo-roman

@aldo-roman aldo-roman commented Sep 8, 2017 •

Copy link
Copy Markdown
Contributor

Closes #3664

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[X] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] angular.io application / infrastructure changes
[ ] Other... Please describe:

What is the current behavior?

Listing an event in a directive without creating an associated EventEmitter instance results in cryptic error.

Issue Number: #3664

What is the new behavior?

Better error messages when an @Output property is not initialized.

Does this PR introduce a breaking change?

[ ] Yes
[X] No

Other information

@googlebot

Copy link
Copy Markdown

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@aldo-roman

Copy link
Copy Markdown
Contributor Author

I signed it!

@googlebot

Copy link
Copy Markdown

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@aldo-roman

Copy link
Copy Markdown
Contributor Author

I signed it! (again)

@googlebot

Copy link
Copy Markdown

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Sep 8, 2017
@cedvdb

cedvdb commented Sep 10, 2017

Copy link
Copy Markdown

Yes, thank you! This thing always gets me

@jasonaden jasonaden added the area: core Issues related to the framework runtime label Nov 14, 2017
@ngbot

ngbot Bot commented Jan 16, 2018

Copy link
Copy Markdown

Hello? Don't want to hassle you. Sure you're busy. But this PR has some merge conflicts that you probably ought to resolve.
That is... if you want it to be merged someday...

@aldo-roman
aldo-roman force-pushed the fix/uninitialized-output-error branch 2 times, most recently from 4800acc to 7b3c139 Compare January 16, 2018 17:31
@splincode

Copy link
Copy Markdown
Contributor

@mhevery Will this pull request be accepted?

@mhevery mhevery added the target: major This PR is targeted for the next major release label Jul 27, 2018
@mhevery
mhevery force-pushed the fix/uninitialized-output-error branch from 7b3c139 to 51ef8a0 Compare July 27, 2018 18:22
@mhevery mhevery added the action: merge The PR is ready for merge by the caretaker label Jul 27, 2018
@ngbot

ngbot Bot commented Jul 27, 2018

Copy link
Copy Markdown

I see that you just added the PR action: merge label, but the following checks are still failing:
    failure missing required status "code-review/pullapprove"
    pending status "ci/circleci: test_ivy_jit" is pending
    pending status "ci/circleci: build-packages-dist" is pending
    pending status "ci/circleci: test_ivy_aot" is pending
    pending status "ci/circleci: lint" is pending
    pending status "ci/circleci: test" is pending
    pending status "google3" is pending
    pending status "continuous-integration/travis-ci/pr" is pending

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@googlebot

Copy link
Copy Markdown

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebot

Copy link
Copy Markdown

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

@mhevery

mhevery commented Jul 27, 2018

Copy link
Copy Markdown
Contributor

Comment thread packages/core/src/view/provider.ts Outdated

@vicb vicb Jul 28, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should explicitely test for not !== null
(ie typeof null === 'object')

@splincode splincode Jul 28, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@vicb fixup (correct detect isObject typeof):

if (outputObservable === Object(outputObservable)) {

@IgorMinar IgorMinar Jul 30, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@splincode did you forget to push the change to the branch? I don't see the fix here. Please check.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oh, I see. @splincode you are not the PR owner. Do I understand correctly that you were just proposing that as the correct fix?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@IgorMinar Yes, exactly, could you make fixup it?

@vicb vicb Jul 31, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

According to MDN:

The Object constructor creates an object wrapper for the given value. If the value is null or undefined, it will create and return an empty object, otherwise, it will return an object of a Type that corresponds to the given value. If the value is an object already, it will return the value.

As we do not want to create a new Object, (obs !== null && typeof obs === 'object') is probably the best ? (arguably we would only create a new object for invalid values)

@trotyl trotyl Jul 31, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@vicb An observable doesn't necessarily be a class instance, but can also be a function (WIP in RxJS v7 for performance consideration), and due to bad JavaScript design typeof a function is not 'object'. Possibly just check not null (!= null instead of !== null) as the issue is for "not initialized".

@splincode splincode Jul 31, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@trotyl Can I just do it this way?

const outputIsObservable = outputObservable && outputObservable.subscribe;
if (outputIsObservable) {
 // ...
}

or simplify

if (outputObservable instanceof Observable) {
 // ...
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@splincode It's already there, no need to duplicate:

export function isObservable(obj: any | Observable<any>): obj is Observable<any> {
// TODO: use Symbol.observable when https://github.com/ReactiveX/rxjs/issues/2415 will be resolved
return !!obj && typeof obj.subscribe === 'function';
}

@splincode splincode Jul 31, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@vicb @trotyl so, simplify

if (isObservable(outputObservable)) {
...
}

@vicb vicb added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Jul 28, 2018
@googlebot

Copy link
Copy Markdown

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebot

Copy link
Copy Markdown

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

@IgorMinar IgorMinar removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Aug 1, 2018
@googlebot

Copy link
Copy Markdown

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebot googlebot added cla: no and removed cla: yes labels Aug 2, 2018
@IgorMinar
IgorMinar force-pushed the fix/uninitialized-output-error branch from 65dc6b6 to 375449e Compare August 2, 2018 15:27
@IgorMinar IgorMinar added cla: yes and removed cla: no labels Aug 2, 2018
@googlebot

Copy link
Copy Markdown

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

@IgorMinar IgorMinar closed this in adf510f Aug 2, 2018
IgorMinar pushed a commit that referenced this pull request Aug 2, 2018
@angular-automatic-lock-bot

Copy link
Copy Markdown

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 Sep 13, 2019
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: core Issues related to the framework runtime cla: yes target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better error messages when an @Output property is not initialized.

9 participants