Skip to content

Commit 4a09956

Browse files
reimplemented error messages when cppcheck is fed incorrect arguments
1 parent 0bcb70a commit 4a09956

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/extension.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,25 @@ async function runCppcheckOnFileXML(
203203

204204
const proc = cp.spawn(commandPath, args);
205205

206+
// if spawn fails (e.g. ENOENT or permission denied)
207+
proc.on("error", (err) => {
208+
console.error("Failed to start cppcheck:", err);
209+
vscode.window.showErrorMessage(`Cppcheck failed to start: ${err.message}`);
210+
});
211+
206212
let xmlOutput = "";
213+
let out = "";
207214
proc.stderr.on("data", d => xmlOutput += d.toString());
208-
proc.on("close", () => {
215+
proc.stdout.on("data", d => out += d.toString());
216+
proc.on("close", code => {
217+
if (code && code > 0) {
218+
// Non-zero code means an error has occured
219+
let errorMessage = `Cppcheck failed with code ${code} (unknown error)`;
220+
if (out.trim().length > 0) {
221+
errorMessage = out.trim();
222+
}
223+
vscode.window.showErrorMessage(errorMessage);
224+
}
209225
const parser = new xml2js.Parser({ explicitArray: true });
210226
parser.parseString(xmlOutput, (err, result) => {
211227
if (err) {

0 commit comments

Comments
 (0)