From ac33af2ece2d6dc87825f96090423724e7ffebbc Mon Sep 17 00:00:00 2001 From: nerix Date: Wed, 5 Nov 2025 02:30:11 +0100 Subject: [PATCH] fix(plugins): Log potential errors in HTTP request callbacks (#6452) Reviewed-by: Mm2PL Reviewed-by: pajlada --- CHANGELOG.md | 1 + src/controllers/plugins/api/HTTPRequest.cpp | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe42436c..1e95368a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Bugfix: Fixed font change not resulting in forced layout update. (#6536) - Bugfix: Fixed scrollbar rect computation potentially resulting in overflows. (#6547) - Bugfix: Forward query params to websocket URLs. (#6141) +- Bugfix: Fixed Lua errors from handlers of HTTP requests not being logged. (#6452) - Dev: Update release documentation. (#6498) - Dev: Make code sanitizers opt in with the `CHATTERINO_SANITIZER_SUPPORT` CMake option. After that's enabled, use the `SANITIZE_*` flag to enable individual sanitizers. (#6493) - Dev: Remove unused QTextCodec includes. (#6487) diff --git a/src/controllers/plugins/api/HTTPRequest.cpp b/src/controllers/plugins/api/HTTPRequest.cpp index 9b4d45e9..44344e5a 100644 --- a/src/controllers/plugins/api/HTTPRequest.cpp +++ b/src/controllers/plugins/api/HTTPRequest.cpp @@ -115,10 +115,9 @@ void HTTPRequest::execute(sol::this_state L) auto hack = this->weak_from_this(); auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L); pl->httpRequests.push_back(this->shared_from_this()); - auto *mainState = pl->state().lua_state(); std::move(this->req_) - .onSuccess([hack](const NetworkResult &res) { + .onSuccess([pl, hack](const NetworkResult &res) { auto self = hack.lock(); if (!self) { @@ -128,10 +127,12 @@ void HTTPRequest::execute(sol::this_state L) { return; } - (*self->cbSuccess)(HTTPResponse(res)); + + loggedVoidCall(*self->cbSuccess, u"HTTPRequest::on_success", pl, + HTTPResponse(res)); self->cbSuccess = std::nullopt; }) - .onError([hack](const NetworkResult &res) { + .onError([pl, hack](const NetworkResult &res) { auto self = hack.lock(); if (!self) { @@ -141,17 +142,17 @@ void HTTPRequest::execute(sol::this_state L) { return; } - (*self->cbError)(HTTPResponse(res)); + loggedVoidCall(*self->cbError, u"HTTPRequest::on_error", pl, + HTTPResponse(res)); self->cbError = std::nullopt; }) - .finally([mainState, hack]() { + .finally([pl, hack]() { auto self = hack.lock(); if (!self) { // this could happen if the plugin was deleted return; } - auto *pl = getApp()->getPlugins()->getPluginByStatePtr(mainState); for (auto it = pl->httpRequests.begin(); it < pl->httpRequests.end(); it++) { @@ -166,7 +167,7 @@ void HTTPRequest::execute(sol::this_state L) { return; } - (*self->cbFinally)(); + loggedVoidCall(*self->cbFinally, u"HTTPRequest::finally", pl); self->cbFinally = std::nullopt; }) .timeout(this->timeout_)