From 6d65f8eea29e371c1c2ca424d27e9f09c401e0fb Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Wed, 19 Nov 2025 01:30:02 +0300 Subject: [PATCH] libstore: Slightly deindent writeCallback by wrapping it in try/catch The indentation level of the code is already high enough. We can just wrap the whole function in a try/catch and mark it noexcept. Partially cherry-picked from https://gerrit.lix.systems/c/lix/+/2133 Co-authored-by: eldritch horrors --- src/libstore/filetransfer.cc | 40 +++++++++++++++++------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index 5acad485c..0ec822e81 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -170,30 +170,28 @@ struct curlFileTransfer : public FileTransfer std::exception_ptr writeException; - size_t writeCallback(void * contents, size_t size, size_t nmemb) - { - try { - size_t realSize = size * nmemb; - result.bodySize += realSize; + size_t writeCallback(void * contents, size_t size, size_t nmemb) noexcept + try { + size_t realSize = size * nmemb; + result.bodySize += realSize; - if (!decompressionSink) { - decompressionSink = makeDecompressionSink(encoding, finalSink); - if (!successfulStatuses.count(getHTTPStatus())) { - // In this case we want to construct a TeeSink, to keep - // the response around (which we figure won't be big - // like an actual download should be) to improve error - // messages. - errorSink = StringSink{}; - } + if (!decompressionSink) { + decompressionSink = makeDecompressionSink(encoding, finalSink); + if (!successfulStatuses.count(getHTTPStatus())) { + // In this case we want to construct a TeeSink, to keep + // the response around (which we figure won't be big + // like an actual download should be) to improve error + // messages. + errorSink = StringSink{}; } - - (*decompressionSink)({(char *) contents, realSize}); - - return realSize; - } catch (...) { - writeException = std::current_exception(); - return 0; } + + (*decompressionSink)({(char *) contents, realSize}); + + return realSize; + } catch (...) { + writeException = std::current_exception(); + return 0; } static size_t writeCallbackWrapper(void * contents, size_t size, size_t nmemb, void * userp)