From 26ef5b10a01b787d412ffeac9b69a28bb30ba3c1 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Thu, 14 May 2026 20:36:44 +1200 Subject: [PATCH 1/2] Check for failed patches --- server/homebrew.api.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index c47e3640e..237d06af7 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -397,19 +397,26 @@ const api = { return res.status(409).send(JSON.stringify({ message: `The server copy is out of sync with the saved brew. Please save your changes elsewhere, refresh, and try again.` })); } + let result = []; try { const patches = parsePatch(brewFromClient.patches); // Patch to a throwaway variable while parallelizing - we're more concerned with error/no error. - const patchedResult = decodeURI(applyPatches(patches, encodeURI(brewFromServer.text))[0]); - if(patchedResult != brewFromClient.text) + result = applyPatches(patches, encodeURI(brewFromServer.text)); + const failedPatches = patches.map((patch, index)=>{if(!result[1][index]){ return patch; }}); + if(failedPatches > 0){ + throw (`Patch failure: ${failedPatches}/${result[1].length} did not apply`); + } + if(decodeURI(result[0]) != brewFromClient.text){ throw ('Patches did not apply cleanly, text mismatch detected'); + } // brew.text = applyPatches(patches, brewFromServer.text)[0]; } catch (err) { debugTextMismatch(brewFromClient.text, brewFromServer.text, `edit/${brewFromClient.editId}`); console.error('Failed to apply patches:', { - //patches : brewFromClient.patches, - brewId : brewFromClient.editId || 'unknown', - error : err + patches : brewFromClient.patches, + result : result, + brewId : brewFromClient.editId || 'unknown', + error : err }); // While running in parallel, don't throw the error upstream. // throw err; // rethrow to preserve the 500 behavior From eec4cf816757775f669b143e7856f303aa733002 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Thu, 14 May 2026 21:17:18 +1200 Subject: [PATCH 2/2] Comment out excessive logging items --- server/homebrew.api.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 237d06af7..afd7d8af9 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -413,10 +413,10 @@ const api = { } catch (err) { debugTextMismatch(brewFromClient.text, brewFromServer.text, `edit/${brewFromClient.editId}`); console.error('Failed to apply patches:', { - patches : brewFromClient.patches, - result : result, - brewId : brewFromClient.editId || 'unknown', - error : err + // patches : brewFromClient.patches, + // result : result, + brewId : brewFromClient.editId || 'unknown', + error : err }); // While running in parallel, don't throw the error upstream. // throw err; // rethrow to preserve the 500 behavior