Skip to content

Commit c26ed98

Browse files
author
Akos Kitta
committed
Better error handling when sketch was not compiled
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent e3166de commit c26ed98

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/extension.ts

Lines changed: 23 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,34 @@ 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+
false;
84+
}
85+
try {
86+
info = JSON.parse(rawStdout);
87+
} catch {
88+
// The CLI does not provide JSON output on error.
89+
vscode.window.showErrorMessage(rawStdout);
90+
}
7191
if (!info) {
7292
return false;
7393
}

0 commit comments

Comments
 (0)