Skip to content

Commit

Permalink
service.ts: improve /exec error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
throwaway96 committed Jan 15, 2024
1 parent 435e68f commit abc028e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion services/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,15 @@ function runService() {
* Executes a shell command and responds with exit code, stdout and stderr.
*/
type ExecPayload = { command: string };
service.register('exec', (message) => {
service.register('exec', (message: Message) => {
if (!('command' in message.payload)) {
message.respond(makeError('missing "command"'));
return;
} else if (typeof message.payload['command'] !== 'string') {
message.respond(makeError('"command" is not a string'));
return;
}

const payload = message.payload as ExecPayload;
child_process.exec(payload.command, { encoding: 'buffer' }, (error, stdout, stderr) => {
const response = {
Expand Down

0 comments on commit abc028e

Please sign in to comment.