Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

angular cannot read property '1' of null is not a useful error message. #10875

Closed
steowens opened this issue Jan 26, 2015 · 10 comments
Closed

angular cannot read property '1' of null is not a useful error message. #10875

steowens opened this issue Jan 26, 2015 · 10 comments

Comments

@steowens
Copy link

What does this error even mean. Error message is not actionable.

@lgalfaso
Copy link
Contributor

can you create a plunker tat shows the error? without this there is not a lot that can be done

@lgalfaso lgalfaso added this to the Backlog milestone Jan 26, 2015
@caitp
Copy link
Contributor

caitp commented Jan 26, 2015

@steowens
Copy link
Author

I think it was caused by the following syntax error on a div tag
`

@caitp
Copy link
Contributor

caitp commented Jan 26, 2015

angular isn't the one parsing the DOM, that's your web browser.

@steowens
Copy link
Author

Why is the error message generated in the angular call stack?

@steowens
Copy link
Author

TypeError: Cannot read property '1' of null
at angular.js:8411
at angular.js:7592
at forEach (angular.js:331)
at nodeLinkFn (angular.js:7579)
at compositeLinkFn (angular.js:7075)
at nodeLinkFn (angular.js:7717)
at angular.js:7953
at processQueue (angular.js:13171)
at angular.js:13187
at Scope.$get.Scope.$eval (angular.js:14384)

@caitp
Copy link
Contributor

caitp commented Jan 26, 2015

Betting on this https://github.com/angular/bower-angular/blob/ecf0435da949836c63ebf048ea8b7710542e33ce/angular.js#L8414-L8416 --- however there's still no way we'd be able to be like "hey your html is screwed up on this line and this column", that's not feasible

@steowens
Copy link
Author

The relevant materials to repro are as follows add the following to index.html

`

`

Add the following to the top level module:
.directive('signupForm', function(){ return { restrict: 'A', templateUrl: '/static/templates/signup-section.html' } })

Add the following to signup-section.html

<div class="content" data-section-content ng-controller="SignupFormController as signupFormCtrl>
</div>

@caitp
Copy link
Contributor

caitp commented Jan 26, 2015

it's pretty clear what the problem is, but we still can't really say where the error happened in your code, we have no way of knowing. best we can do is say "hey, you screwed up your controller name somewhere"

@steowens
Copy link
Author

Here is the code where the exception gets thrown:

if (isString(expression)) { match = expression.match(CNTRL_REG), constructor = match[1], identifier = identifier || match[3]; expression = controllers.hasOwnProperty(constructor)

It fails on constructor=match[1] You are not testing for a proper match here by the way and you are tossing an error way up the stack.

The input to the function contains the following value in expression:

"SignupFormController as signupFormCtrl>
    <div class="

So rather than punting the exception up the stack if you were to do something about catching the exeption in match, then wrapping it with contextual information provided by the value of expression you could make the error a thousand times more informative.

@caitp caitp self-assigned this Jan 26, 2015
caitp added a commit to caitp/angular.js that referenced this issue Jan 29, 2015
Previously, the error was a JS runtime error when trying to access a property of `null`. But, it's
a bit nicer to throw a real error and provide a description of how to fix it. Developer ergonomics
and all that.

Closes angular#10875
caitp added a commit that referenced this issue Jan 29, 2015
Previously, the error was a JS runtime error when trying to access a property of `null`. But, it's
a bit nicer to throw a real error and provide a description of how to fix it. Developer ergonomics
and all that.

Closes #10875
Closes #10910
@caitp caitp closed this as completed in dda65e9 Jan 29, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.