diff --git a/packages/api/server/ws.mts b/packages/api/server/ws.mts index 003e008ee..335483184 100644 --- a/packages/api/server/ws.mts +++ b/packages/api/server/ws.mts @@ -435,17 +435,27 @@ async function cellFormat(payload: CellFormatPayloadType) { } const result = await formatAndUpdateCodeCell(session, cellBeforeUpdate); if (!result.success) { - return sendCellUpdateError(session, payload.cellId, result.errors); - } - - const cell = result.cell as CodeCellType; + wss.broadcast(`session:${session.id}`, 'cell:output', { + cellId: payload.cellId, + output: { type: 'stderr', data: result.errors }, + }); + sendCellUpdateError(session, payload.cellId, [ + { + message: + 'An error occurred while formatting the code. Please check the "stderr" for more details.', + attribute: 'formatting', + }, + ]); + } else { + const cell = result.cell as CodeCellType; - wss.broadcast(`session:${session.id}`, 'cell:formatted', { - cellId: payload.cellId, - cell, - }); + wss.broadcast(`session:${session.id}`, 'cell:formatted', { + cellId: payload.cellId, + cell, + }); - refreshCodeCellDiagnostics(session, cell); + refreshCodeCellDiagnostics(session, cell); + } } async function cellUpdate(payload: CellUpdatePayloadType) { diff --git a/packages/api/session.mts b/packages/api/session.mts index b42204913..04a879842 100644 --- a/packages/api/session.mts +++ b/packages/api/session.mts @@ -336,10 +336,10 @@ export async function formatCode(dir: string, fileName: string) { const command = `npx prettier ${codeFilePath}`; return new Promise((resolve, reject) => { - exec(command, async (error, stdout) => { - if (error) { - console.error(`exec error: ${error}`); - reject(error); + exec(command, async (_, stdout, stderr) => { + if (stderr) { + console.error(`exec error: ${stderr}`); + reject(stderr); return; } resolve(stdout); @@ -357,7 +357,7 @@ export async function formatAndUpdateCodeCell(session: SessionType, cell: CodeCe } catch (error) { return Promise.resolve({ success: false, - errors: [{ message: 'An error occurred formatting the code.', attribute: 'formatting' }], + errors: error, } as UpdateResultType); } }