diff --git a/backend/src/facades/commandExecutionFacade.js b/backend/src/facades/commandExecutionFacade.js index ac749b16..c0e42d1a 100644 --- a/backend/src/facades/commandExecutionFacade.js +++ b/backend/src/facades/commandExecutionFacade.js @@ -47,12 +47,16 @@ function getConnectionStatus() { */ function executeCommand(cmd, onData, onEnd = () => {}, onError = () => {}, accumulateOutput = false) { if (process.env.CONNECTION_TYPE === CONNECTION_TYPE.LOCAL) { - // RUN ON LOCAL MACHINE const child = exec(cmd); + let stdoutData = ''; let stderrData = ''; child.stdout.on('data', (data) => { - onData(data.toString()); + if (accumulateOutput) { + stdoutData += data.toString(); + } else { + onData(data.toString()); + } }); child.stderr.on('data', (data) => { @@ -64,12 +68,11 @@ function executeCommand(cmd, onData, onEnd = () => {}, onError = () => {}, accum const errorMessage = `Process exited with code ${code}` + (stderrData ? `: ${stderrData}` : ''); onError(errorMessage); } else { - onEnd(); + onEnd(accumulateOutput ? stdoutData : undefined); } }); child.on('error', (err) => { - // Handling process spawning errors onError(`Failed to start subprocess: ${err.message}`); }); } else { diff --git a/backend/src/router/modelsRouter.js b/backend/src/router/modelsRouter.js index da5ed17a..f5c2cc3c 100644 --- a/backend/src/router/modelsRouter.js +++ b/backend/src/router/modelsRouter.js @@ -126,25 +126,18 @@ router.get('/models-list/:type', checkSshConnection, (req, res) => { isTrained: files.includes(modelName) })); - res.status(OK).send(modelsWithTrainingInfo); - }, - () => { - const modelsAreNotTrained = models.map((modelName) => ({ - name: modelName, - isTrained: false - })); - - res.status(OK).send(modelsAreNotTrained); + return res.status(OK).send(modelsWithTrainingInfo); }, + () => {}, (error) => { - if (error.includes('No such file or directory')) { + if (!error || error.includes('No such file or directory')) { const modelsWithTrainingInfo = models.map((modelName) => ({ name: modelName, isTrained: false })); - res.status(OK).send(modelsWithTrainingInfo); + return res.status(OK).send(modelsWithTrainingInfo); } else { - res.status(INTERNAL_SERVER_ERROR).send({ error: `Error listing model checkpoint files: ${error}` }); + return res.status(INTERNAL_SERVER_ERROR).send({ error: `Error listing model checkpoint files: ${error}` }); } } );