From b5e3efc8cc4a38f581d513e085f30bc221336ab7 Mon Sep 17 00:00:00 2001 From: chsami <23292806+chsami@users.noreply.github.com> Date: Wed, 7 Oct 2026 22:31:09 +0200 Subject: [PATCH] fix(microbot): requeue error batch when submit throws; close response first CodeRabbit on #1901: if building the upload request throws synchronously (e.g. a malformed -Dmicrobot.apiUrl) the drained batch was lost; requeue it before rethrowing. Close the HTTP response before running the rejection callback so a throwing callback cannot leak it. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01PKz6YjDRJdva762xPzTaia --- .../runelite/client/plugins/microbot/MicrobotApi.java | 8 +++++--- .../microbot/diagnostics/ScriptErrorReporter.java | 10 +++++++++- .../microbot/diagnostics/ScriptErrorReporterTest.java | 9 +++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/MicrobotApi.java b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/MicrobotApi.java index 97d017fab7..4e2e4105b1 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/MicrobotApi.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/MicrobotApi.java @@ -127,12 +127,14 @@ public void onFailure(Call call, IOException e) @Override public void onResponse(Call call, Response response) { - if (!response.isSuccessful()) + boolean successful = response.isSuccessful(); + int code = response.code(); + response.close(); + if (!successful) { - log.debug("Error telemetry upload rejected: HTTP {}", response.code()); + log.debug("Error telemetry upload rejected: HTTP {}", code); onRejected.run(); } - response.close(); } }); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/diagnostics/ScriptErrorReporter.java b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/diagnostics/ScriptErrorReporter.java index ad4424a41d..d9a37b78c2 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/microbot/diagnostics/ScriptErrorReporter.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/microbot/diagnostics/ScriptErrorReporter.java @@ -153,7 +153,15 @@ private void send() payload.addProperty("osName", System.getProperty("os.name")); payload.addProperty("osArch", System.getProperty("os.arch")); payload.add("errors", errors); - microbotApi.submitErrors(payload, () -> requeue(errors)); + try + { + microbotApi.submitErrors(payload, () -> requeue(errors)); + } + catch (RuntimeException e) + { + requeue(errors); + throw e; + } } public void rememberPlayerName(String name) diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/microbot/diagnostics/ScriptErrorReporterTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/microbot/diagnostics/ScriptErrorReporterTest.java index 4e2b75375a..f524a8d64b 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/microbot/diagnostics/ScriptErrorReporterTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/microbot/diagnostics/ScriptErrorReporterTest.java @@ -193,6 +193,15 @@ public void requeuesRejectedBatch() assertEquals(2, captor.getValue().getAsJsonArray("errors").get(0).getAsJsonObject().get("count").getAsInt()); } + @Test + public void requeuesBatchWhenSubmitThrows() + { + org.mockito.Mockito.doThrow(new IllegalArgumentException("bad url")).when(api).submitErrors(any(), any()); + log(Level.ERROR, "loop failed", boom()); + reporter.flush(); + assertEquals(1, reporter.pendingCount()); + } + @Test public void groupsMessagesThatOnlyDifferInNumbers() {