Skip to content

feat(DirectiveParser): throw errors when expected directives are not...#570

Closed
b-laporte wants to merge 1 commit into
angular:masterfrom
b-laporte:directive_validation
Closed

feat(DirectiveParser): throw errors when expected directives are not...#570
b-laporte wants to merge 1 commit into
angular:masterfrom
b-laporte:directive_validation

Conversation

@b-laporte

Copy link
Copy Markdown

... present (i.e. when non-root templates have no directive or when invalid DOM properties that are associated to an expression are not matched by any directive...)

fix #527

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.

StringMapWrapper would be faster (ES5) if keys are string

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Indeed - I will do the change asap.

@b-laporte b-laporte force-pushed the directive_validation branch from dac45a1 to b7e0ed8 Compare February 9, 2015 17:30

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.

Could the error message include the Element HTML so that developer would know where to go to fix it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I updated the PR with more explicit context information. For the time being it is a simple HTML description - but if we move to a JS parser (cf. webworkers) the generated DOM could include meta-data for each element such as file name, line and column numbers that could be then used for even more meaningful messages.

@mhevery

mhevery commented Feb 10, 2015

Copy link
Copy Markdown
Contributor

Looks good to me, but I would like @tbosch to take another look.

@mhevery mhevery added @lgtm action: merge The PR is ready for merge by the caretaker labels Feb 11, 2015
@mhevery mhevery modified the milestone: M5: Early Adopters Feb 11, 2015
@b-laporte b-laporte force-pushed the directive_validation branch 4 times, most recently from 85d56a8 to 2676e69 Compare February 15, 2015 21:59
@b-laporte

Copy link
Copy Markdown
Author

I did a few refactoring since the first review:

  • tests have been moved to integration tests to not create false positives while mocking the first compilation steps (that are also involved in error handling btw.)
  • a helper has been added on NgElement to generate the element description that is included in each error message (maybe there could be a better place for this helper?)
  • it seems like the Promise.catch is not properly transpiled to Future.catchError in DART - this is why some tests are skipped in dart in this PR (cf. isObject({}) test) as I didn't find any way to have tests running on both environments (if I use catch() instead of then() the dart code will not even load - this is why I used the Promise.then form in the tests)

I also realised that the DOM.attributeMap() method was relying on a Map and not a StringMap - any reason for this? I guess this could be changed for better performances?

@tbosch I think I am done with this PR - so feel free to comment - thx 😃

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.

We should fill this already here, not and lazily by a compile step, as previous compile steps might have changed the element already. Also, this should include the compilationUnit. Right now we pass the compilationUnit as constructor argument into some steps (e.g. PropertyBindingParser), so we can provide a more meaningful error when parsing expressions. But we should actually also use the elementDescription + compilationUnit there as well.

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.

I.e. remove the compilationUnit from the constructors of the various compile steps and include it in the elementDescription, then use the new elementDescription where the compilationUnit was used before.

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.

Only if assertionsEnabled() though...

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.

Don't use a generic fail method, but provide an error description at the place where you want to fail (e.g. should not have come here as an exception was expected, ...)

@tbosch

tbosch commented Feb 18, 2015

Copy link
Copy Markdown
Contributor

LGTM, besides the mentioned changes. Also needs rebase ontop of master...

@tbosch tbosch 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 Feb 18, 2015
@b-laporte

Copy link
Copy Markdown
Author

thanks for the comments - I will provide an update in the coming days (unfortunately don't have much time right now..)

@tbosch

tbosch commented Feb 19, 2015

Copy link
Copy Markdown
Contributor

Thanks!
On Thu, Feb 19, 2015 at 12:58 AM Bertrand Laporte notifications@github.com
wrote:

thanks for the comments - I will provide an update in the coming days
(unfortunately don't have much time right now..)


Reply to this email directly or view it on GitHub
#570 (comment).

@b-laporte b-laporte force-pushed the directive_validation branch from 2676e69 to 8995a73 Compare February 22, 2015 18:14
@b-laporte

Copy link
Copy Markdown
Author

OK - cleanup done according to @tbosch comments. Some more comments regarding this PR:

  • the compile element element description is now calculated in compile_element but is still overridden in view_splitter for template elements that are created dynamically so that users get a meaningful error messages (otherwise messages will mention elements that don't appear in the original template file)
  • In element_binder_builder I cannot write const STYLE_ATTR = 'style';const STYLE_PREFIX = STYLE_ATTR + '.'; as I get the following error with DART: dart error: initializer is not a valid compile-time constant
  • I preferred to keep some of the test in integration_spec as the code handling the errors in spread in view_splitter, directive_parser, compile_element and element_binder_builder. It also reduces the risk to create false positives (i.e. errors than cannot happen in real life but that can be generated through incomplete mocks) - and the error validation will be easier to maintain while the code evolves as samples represent what users will write in real templates.
  • regarding isSpecialProperty() (new name of previous isValidProperty), I originally thought that DOM.hasProperty() was checking for valid properties - whereas I just realized it checks for attributes (so I guess name should be DOM.hasAttribute) - this is why in my original version I was checking role , class and style which are valid attributes, but not properties.

@b-laporte b-laporte force-pushed the directive_validation branch from 8995a73 to acdf898 Compare February 22, 2015 20:27
@b-laporte b-laporte force-pushed the directive_validation branch from acdf898 to c87fd04 Compare February 22, 2015 20:58
b-laporte pushed a commit that referenced this pull request Feb 24, 2015
@b-laporte b-laporte closed this in 94e203b Feb 25, 2015
b-laporte pushed a commit to b-laporte/angular that referenced this pull request Feb 25, 2015
b-laporte pushed a commit that referenced this pull request Feb 25, 2015
@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 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews action: merge The PR is ready for merge by the caretaker cla: yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Throw errors when binding to a property which is not found on an element in dev mode.

6 participants