istanbuljs / nyc

the Istanbul command line interface
https://istanbul.js.org/
ISC License
5.54k stars 353 forks source link

Inconsistency in .nyc_output causing nyc annotator crash #1527

Open keminming opened 10 months ago

keminming commented 10 months ago

Hi, we've seen nyc annotator crash on undefined object: Cannot read properties of undefined (reading 'start') TypeError: Cannot read properties of undefined (reading 'start') at /private/var/jenkins/workspace/dcxjs_kwang_dcx-9771/node_modules/istanbul-reports/lib/html/annotator.js:51:31 at Array.forEach () at annotateStatements (/private/var/jenkins/workspace/dcxjs_kwang_dcx-9771/node_modules/istanbul-reports/lib/html/annotator.js:48:36) at annotateSourceCode (/private/var/jenkins/workspace/dcxjs_kwang_dcx-9771/node_modules/istanbul-reports/lib/html/annotator.js:235:9) at HtmlReport.onDetail (/private/var/jenkins/workspace/dcxjs_kwang_dcx-9771/node_modules/istanbul-reports/lib/html/index.js:409:33) at LcovReport. [as onDetail] (/private/var/jenkins/workspace/dcxjs_kwang_dcx-9771/node_modules/istanbul-reports/lib/lcov/index.js:28:23) at Visitor.value (/private/var/jenkins/workspace/dcxjs_kwang_dcx-9771/node_modules/istanbul-lib-report/lib/tree.js:38:38) at ReportNode.visit (/private/var/jenkins/workspace/dcxjs_kwang_dcx-9771/node_modules/istanbul-lib-report/lib/tree.js:88:21) at /private/var/jenkins/workspace/dcxjs_kwang_dcx-9771/node_modules/istanbul-lib-report/lib/tree.js:92:19 at Array.forEach ()

That's because the size of the statementMap doesn't match the size of s for checkRetriable.ts: "/private/var/jenkins/workspace/dcxjs_kwang_dcx-9771/packages/util/src/checkRetriable.ts": { "path": "/private/var/jenkins/workspace/dcxjs_kwang_dcx-9771/packages/util/src/checkRetriable.ts", "statementMap": { "0": { "start": { "line": 23, "column": 35 }, "end": { "line": 23, "column": 74 } }, "1": { "start": { "line": 25, "column": 18 }, "end": { "line": 25, "column": 108 } }, "2": { "start": { "line": 25, "column": 55 }, "end": { "line": 25, "column": 108 } }, "3": { "start": { "line": 26, "column": 20 }, "end": { "line": 27, "column": 83 } }, "4": { "start": { "line": 27, "column": 4 }, "end": { "line": 27, "column": 83 } }, "5": { "start": { "line": 33, "column": 4 }, "end": { "line": 35, "column": null } }, "6": { "start": { "line": 34, "column": 8 }, "end": { "line": 34, "column": 21 } }, "7": { "start": { "line": 37, "column": 4 }, "end": { "line": 39, "column": 42 } }, **"8": { "start": { "line": 38, "column": 41 }, "end": { "line": 38, "column": 71 } }** }, "fnMap": { "0": { "name": "(anonymous_0)", "decl": { "start": { "line": 25, "column": 18 }, "end": { "line": 25, "column": 19 } }, "loc": { "start": { "line": 25, "column": 55 }, "end": { "line": 25, "column": 108 } } }, "1": { "name": "(anonymous_1)", "decl": { "start": { "line": 26, "column": 20 }, "end": { "line": 26, "column": 21 } }, "loc": { "start": { "line": 27, "column": 4 }, "end": { "line": 27, "column": 83 } } }, "2": { "name": "checkRetriable", "decl": { "start": { "line": 29, "column": 16 }, "end": { "line": 29, "column": 30 } }, "loc": { "start": { "line": 31, "column": 75 }, "end": { "line": 40, "column": 1 } } }, "3": { "name": "(anonymous_3)", "decl": { "start": { "line": 38, "column": 26 }, "end": { "line": 38, "column": 27 } }, "loc": { "start": { "line": 38, "column": 41 }, "end": { "line": 38, "column": 71 } } } }, "branchMap": { "0": { "loc": { "start": { "line": 25, "column": 55 }, "end": { "line": 25, "column": 76 } }, "type": "binary-expr", "locations": [ { "start": { "line": 25, "column": 55 }, "end": { "line": 25, "column": 76 } }, { "start": { "line": 25, "column": 80 }, "end": { "line": 25, "column": 108 } } ] }, "1": { "loc": { "start": { "line": 27, "column": 27 }, "end": { "line": 27, "column": 60 } }, "type": "cond-expr", "locations": [ { "start": { "line": 27, "column": 27 }, "end": { "line": 27, "column": 60 } }, { "start": { "line": 27, "column": 63 }, "end": { "line": 27, "column": 83 } } ] }, "2": { "loc": { "start": { "line": 31, "column": 56 }, "end": { "line": 31, "column": 75 } }, "type": "default-arg", "locations": [ { "start": { "line": 31, "column": 56 }, "end": { "line": 31, "column": 75 } } ] }, "3": { "loc": { "start": { "line": 33, "column": 4 }, "end": { "line": 35, "column": null } }, "type": "if", "locations": [ { "start": { "line": 33, "column": 4 }, "end": { "line": 35, "column": null } }, { "start": { "line": 33, "column": 4 }, "end": { "line": 35, "column": null } } ] }, "4": { "loc": { "start": { "line": 38, "column": 10 }, "end": { "line": 38, "column": 72 } }, "type": "cond-expr", "locations": [ { "start": { "line": 38, "column": 10 }, "end": { "line": 38, "column": 72 } }, { "start": { "line": 39, "column": 10 }, "end": { "line": 39, "column": 41 } } ] } }, "s": { "0": 7, "1": 7, "2": 0, "3": 7, "4": 0, "5": 0, "6": 0, "7": 0, "8": 0, **"9": null** }, "f": { "0": 0, "1": 0, "2": 0, "3": 0 }, "b": { "0": [ 0, 0 ], "1": [ 0, 0 ], "2": [ 0 ], "3": [ 0, 0 ], "4": [ 0, 0 ] } },

NOTE the value of last entry in s is null which is very abnormal.

Is there a way further tracking down the issue?

steoj commented 8 months ago

I can reproduce this when trying to merge two reports into one (from jest & cypress) when the coverage reports have entries for the same file. Removing reference to files so that a file record only occurs in one of the reports, fixes the problem.