handle devchat not found error

This commit is contained in:
bobo.yang 2023-05-19 16:12:22 +08:00
parent 94413e6f1f
commit 8dcc4e4a6e
2 changed files with 18 additions and 4 deletions

View File

@ -2,7 +2,7 @@
"name": "devchat",
"displayName": "DevChat",
"description": "Write prompts, not code",
"version": "0.0.42",
"version": "0.0.45",
"icon": "assets/devchat.png",
"publisher": "merico",
"engines": {
@ -23,6 +23,7 @@
"dist/*",
"bin/*",
"assets/*",
"tools/*",
"workflows/*",
"LICENSE",
"README.md"

View File

@ -57,17 +57,17 @@ class DevChat {
let stdout = '';
let stderr = '';
this.childProcess.stdout.on('data', (data: { toString: () => any; }) => {
const dataStr = data.toString();
onData(dataStr);
stdout += dataStr;
});
this.childProcess.stderr.on('data', (data: string) => {
stderr += data;
});
this.childProcess.on('close', (code: number) => {
if (stderr) {
logger.channel()?.error(stderr);
@ -80,6 +80,18 @@ class DevChat {
reject({ code, stdout, stderr });
}
});
// Add error event listener to handle command not found exception
this.childProcess.on('error', (error: any) => {
if (error.code === 'ENOENT') {
logger.channel()?.error(`Command not found: ${command}`);
logger.channel()?.show();
} else {
logger.channel()?.error(`Error occurred: ${error.message}`);
logger.channel()?.show();
}
reject({ code: error.code, stdout: "", stderr: error.message });
});
});
};
@ -290,6 +302,7 @@ class DevChat {
},
}, (partialResponse: string) => { });
logger.channel()?.info(`Finish devchat with args: ${args.join(" ")}`);
if (stderr) {
logger.channel()?.error(`Error getting log: ${stderr}`);
logger.channel()?.show();