Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e4ef8ed

Browse filesBrowse files
authored
Merge pull request #5 from arduino/better-error-handling-when-not-compiled
Better error handling when sketch was not compiled
2 parents e3166de + ed8620c commit e4ef8ed
Copy full SHA for e4ef8ed

File tree

Expand file treeCollapse file tree

1 file changed

+22
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+22
-3
lines changed

‎src/extension.ts

Copy file name to clipboardExpand all lines: src/extension.ts
+22-3Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { posix } from 'path';
2+
import { spawnSync } from 'child_process';
13
import deepEqual from 'deep-equal';
24
import WebRequest from 'web-request';
3-
import { spawnSync } from 'child_process';
45
import vscode, { ExtensionContext } from 'vscode';
56
import { LanguageClient, CloseAction, ErrorAction, InitializeError, Message, RevealOutputChannelOn } from 'vscode-languageclient';
67

@@ -59,15 +60,33 @@ export function activate(context: ExtensionContext) {
5960

6061
async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boolean> {
6162
let info: DebugInfo | undefined = undefined;
63+
let rawStdout: string | undefined = undefined;
64+
let rawStdErr: string | undefined = undefined;
6265
try {
6366
const args = ['debug', '-I', '-b', config.board.fqbn, config.sketchPath, '--format', 'json'];
64-
const rawInfo = spawnSync(config.cliPath, args, { encoding: 'utf8' }).stdout.trim();
65-
info = JSON.parse(rawInfo);
67+
const { stdout, stderr } = spawnSync(config.cliPath, args, { encoding: 'utf8' });
68+
rawStdout = stdout.trim();
69+
rawStdErr = stderr.trim();
6670
} catch (err) {
6771
const message = err instanceof Error ? err.stack || err.message : 'Unknown error';
6872
vscode.window.showErrorMessage(message);
6973
return false;
7074
}
75+
if (!rawStdout) {
76+
if (rawStdErr) {
77+
if (rawStdErr.indexOf('compiled sketch not found in') !== -1) {
78+
vscode.window.showErrorMessage(`Sketch '${posix.basename(config.sketchPath)}' was not compiled. Please compile the sketch and start debugging again.`);
79+
} else {
80+
vscode.window.showErrorMessage(rawStdErr);
81+
}
82+
}
83+
return false;
84+
}
85+
try {
86+
info = JSON.parse(rawStdout);
87+
} catch (err) {
88+
vscode.window.showErrorMessage(err);
89+
}
7190
if (!info) {
7291
return false;
7392
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.