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

Error running istanbul check-coverage --statements 90 #192

Open
leore opened this issue Apr 20, 2014 · 9 comments
Open

Error running istanbul check-coverage --statements 90 #192

leore opened this issue Apr 20, 2014 · 9 comments

Comments

@leore
Copy link

leore commented Apr 20, 2014

Getting this error:

/Users/bavidar/.nvm/v0.10.26/lib/node_modules/istanbul/lib/object-utils.js:58
var line = statementMap[st].start.line,
^
TypeError: Cannot read property 'start' of undefined

Has anyone solves this problem?

@guyellis
Copy link

guyellis commented Apr 9, 2015

@leore - Is this still an issue for you? I think that it's an easy fix that I can do an submit a PR for if it's still an issue for you or someone else.

@chengyin
Copy link

I hit this problem recently. What solutions do you have in mind if you don't mind me asking, @guyellis?

@guyellis
Copy link

https://github.com/gotwarlost/istanbul/blob/master/lib/object-utils.js#L59

@chengyin I was going to skip that section of code if statementMap[st] was falsey. Thought that would be better than having it fail.

Are you hitting this error as well?

@gotwarlost
Copy link
Owner

This is most probably because it is trying to process a Json file that doesn't have coverage info. The error message is terrible and doesn't indicate which gold had the problem. If you want to submit a pr, you should probably focus on improving the message and / or skipping files that don't look like a coverage json

@chengyin
Copy link

I did some investigation and this is what I got for our specific case:

The issue is caused by a mismatch between statements and statementsMap. The length of the two didn’t agree. One recorded more statements than the other for the same file.

I dug deeper and in our codebase, this is because we are using webpack inject-loader for our unit tests. If the injected version and the original version both get required, then there are two files registered to the same filename in Istanbul. The extra code for injection threw Istanbul off and eventually caused the exception.

Now that’s an issue that Istanbul doesn’t and probably shouldn’t deal with. There are multiple places in Istanbul runs into exceptions because of this. I agree better error message would help.

I plan to fork inject-loader and add Istanbul ignore comments for the injection related code. A different inject loader does this.

@guyellis
Copy link

@chengyin I agree with @gotwarlost - would be great to also submit a PR for istanbul that did one or more of:

  • improved the message
  • skip files that don't look like coverage
  • and based on your use case also
    • checked that the lengths of statements and statementsMap were the same or printed an error
    • or did some checking while iterating through each one so that missing properties weren't use as in my previous comment.

As per my previous "fix" idea my feeling is that istanbul should still try and work and give a partially good result if not complete one while printing out error messages about what it can't do while processing.

i.e. given a choice between:

  • complete failure with no result and a good error message
    • AND
  • partial failure with some result and a good error message
    I'd take the latter

@ianribas
Copy link

Just so it may help others with the same error message, I had the same problem and it was a similar situation as the one reported by @chengyin: the same file with two different coverage information.

As we use broserify, the first was coming from a browserify transform (with browserify-istanbul) and the other from the karma-coverage preprocessor. Turns out, of course, the second is unnecessary and was causing problems when generating the report.

@silkentrance
Copy link

@gotwarlost since this is basically a mistake in the build process and also related to an external library, we should close this for good, don't you think?

@silkentrance
Copy link

@gotwarlost or create an FAQ from it?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants