From 36f4e290d0f95f7df080bffc987375fd97d6c818 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Wed, 19 Nov 2025 02:22:23 +0300 Subject: [PATCH] libstore/filetransfer: Add more context to error message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now the error message looks something like: error: … during upload of 'file:///tmp/storeabc/4yxrw9flcvca7f3fs7c5igl2ica39zaw.narinfo' error: blah blah Also makes fail and failEx themselves noexcept, since all the operations they do are noexcept and we don't want exceptions escaping from them. --- src/libstore/filetransfer.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index 407b087c9..709cdaffb 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -151,15 +151,23 @@ struct curlFileTransfer : public FileTransfer } } - void failEx(std::exception_ptr ex) + void failEx(std::exception_ptr ex) noexcept { assert(!done); done = true; + try { + std::rethrow_exception(ex); + } catch (nix::Error & e) { + /* Add more context to the error message. */ + e.addTrace({}, "during %s of '%s'", Uncolored(request.verb()), request.uri.to_string()); + } catch (...) { + /* Can't add more context to the error. */ + } callback.rethrow(ex); } template - void fail(T && e) + void fail(T && e) noexcept { failEx(std::make_exception_ptr(std::forward(e))); }