Skip to content

Commit

Permalink
fix: Surround xml2js parsing with try catch block (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vigilans authored and jdneo committed Sep 25, 2019
1 parent c8d1710 commit d9dc7a9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as fse from 'fs-extra';
import * as path from 'path';
import { Uri, window, workspace, WorkspaceFolder } from 'vscode';
import * as xmljs from 'xml-js';
import { checkstyleChannel } from '../checkstyleChannel';
import { BuiltinConfiguration, checkstyleDoctypeIds } from '../constants/checkstyleConfigs';
import { IQuickPickItemEx } from '../models';
import { getDefaultWorkspaceFolder, setCheckstyleConfigurationPath, tryUseWorkspaceFolder } from '../utils/settingUtils';
Expand Down Expand Up @@ -103,7 +104,11 @@ async function detectConfigurations(): Promise<IQuickPickItemEx[]> {
}
}
}
xmljs.xml2js(await fse.readFile(xml.fsPath, 'utf8'), { doctypeFn });
try {
xmljs.xml2js(await fse.readFile(xml.fsPath, 'utf8'), { doctypeFn });
} catch (error) { // Skip this xml, continue detecting process
checkstyleChannel.appendLine(`Parse failed: ${xml}`);
}
}
return detected;
}

0 comments on commit d9dc7a9

Please sign in to comment.