|
| 1 | +import { posix } from 'path'; |
| 2 | +import { spawnSync } from 'child_process'; |
1 | 3 | import deepEqual from 'deep-equal';
|
2 | 4 | import WebRequest from 'web-request';
|
3 | | -import { spawnSync } from 'child_process'; |
4 | 5 | import vscode, { ExtensionContext } from 'vscode';
|
5 | 6 | import { LanguageClient, CloseAction, ErrorAction, InitializeError, Message, RevealOutputChannelOn } from 'vscode-languageclient';
|
6 | 7 |
|
@@ -59,15 +60,33 @@ export function activate(context: ExtensionContext) {
|
59 | 60 |
|
60 | 61 | async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boolean> {
|
61 | 62 | let info: DebugInfo | undefined = undefined;
|
| 63 | + let rawStdout: string | undefined = undefined; |
| 64 | + let rawStdErr: string | undefined = undefined; |
62 | 65 | try {
|
63 | 66 | 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(); |
66 | 70 | } catch (err) {
|
67 | 71 | const message = err instanceof Error ? err.stack || err.message : 'Unknown error';
|
68 | 72 | vscode.window.showErrorMessage(message);
|
69 | 73 | return false;
|
70 | 74 | }
|
| 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 | + } |
71 | 90 | if (!info) {
|
72 | 91 | return false;
|
73 | 92 | }
|
|
0 commit comments