Skip to content

Commit

Permalink
Address #364: catch errors per-section
Browse files Browse the repository at this point in the history
In #364, I accidentally produced a file that (apparently) has empty
section filenames, as understood by the extension. This lead to an
undefined property access (`split`) when trying to work with the file
name; that exception propagated all the way up the rendering stack,
resulting in _no_ coverage being displayed.

With this change, if we encounter an error in `checkSection`, we just return
`false` - if it's an erroneous section, it doesn't apply to the current
file. (This is especially true if there is no `section.file` property!)

This way, we still show coverage wherever we can.
  • Loading branch information
cceckman committed Apr 27, 2022
1 parent a757959 commit 7192fb9
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/coverage-system/sectionfinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,22 @@ export class SectionFinder {
* @param section data section to check against filename
* @param editorFileRelative normalized relative path (against workspace folder) of editor filename, starts with ###
* @param workspaceFolderName workspace folder name
* @returns true iff this section matches (applies to) the provided editorRelativeFile
*/
private checkSection(section: Section, editorFileRelative: string, workspaceFolderName: string): boolean {
// Check if we need to swap any fragments of the file path with a remote fragment
// IE: /var/www/ -> /home/me/
const sectionFileName = this.resolveFileName(section.file);
if (!isPathAbsolute(sectionFileName)) {
return this.checkSectionRelative(sectionFileName, editorFileRelative);
} else {
return this.checkSectionAbsolute(sectionFileName, editorFileRelative, workspaceFolderName);
try {
// Check if we need to swap any fragments of the file path with a remote fragment
// IE: /var/www/ -> /home/me/
const sectionFileName = this.resolveFileName(section.file);
if (!isPathAbsolute(sectionFileName)) {
return this.checkSectionRelative(sectionFileName, editorFileRelative);
} else {
return this.checkSectionAbsolute(sectionFileName, editorFileRelative, workspaceFolderName);
}
} catch (error) {
const checkSectionError = `[${Date.now()}][renderer]: ignoring section: error from check: ${error}`;
this.outputChannel.appendLine(checkSectionError);
return false;
}
}

Expand Down

0 comments on commit 7192fb9

Please sign in to comment.