From 83cd1d2545b2522fe69b740c9d2a6006506e80bc Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Fri, 13 Jun 2025 01:26:06 -0600 Subject: [PATCH] Improve logging of prettier errors (#32665) In particular, seems like the error message and the message sent to prettier were mixed up before Release Notes: - N/A --- crates/prettier/src/prettier.rs | 5 ++--- crates/prettier/src/prettier_server.js | 9 ++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/prettier/src/prettier.rs b/crates/prettier/src/prettier.rs index 3c8cee6320..d265f099fb 100644 --- a/crates/prettier/src/prettier.rs +++ b/crates/prettier/src/prettier.rs @@ -452,14 +452,13 @@ impl Prettier { }, }) })? - .context("prettier params calculation")?; + .context("building prettier request")?; let response = local .server .request::(params) .await - .into_response() - .context("prettier format")?; + .into_response()?; let diff_task = buffer.update(cx, |buffer, cx| buffer.diff(response.text, cx))?; Ok(diff_task.await) } diff --git a/crates/prettier/src/prettier_server.js b/crates/prettier/src/prettier_server.js index 12a24863ea..6799b4aceb 100644 --- a/crates/prettier/src/prettier_server.js +++ b/crates/prettier/src/prettier_server.js @@ -52,18 +52,17 @@ async function handleBuffer(prettier) { try { message = JSON.parse(messageText); } catch (e) { - sendResponse(makeError(`Failed to parse message '${messageText}': ${e}`)); + sendResponse(makeError(`Parse error in request message: ${e}\nMessage: ${messageText}`)); continue; } // allow concurrent request handling by not `await`ing the message handling promise (async function) handleMessage(message, prettier).catch((e) => { - const errorMessage = message; - if ((errorMessage.params || {}).text !== undefined) { - errorMessage.params.text = "..snip.."; + if ((message.params || {}).text !== undefined) { + message.params.text = "..snip.."; } sendResponse({ id: message.id, - ...makeError(`error during message '${JSON.stringify(errorMessage)}' handling: ${e}`), + ...makeError(`${e}\nWhile handling prettier request: ${JSON.stringify(message)}`), }); }); }