Skip to content

Refactor enqueueFileTransfer#420

Open
proski wants to merge 1 commit intoDeterminateSystems:filetransfer-enqueue-exceptionsfrom
proski:refactor-enqueueFileTransfer
Open

Refactor enqueueFileTransfer#420
proski wants to merge 1 commit intoDeterminateSystems:filetransfer-enqueue-exceptionsfrom
proski:refactor-enqueueFileTransfer

Conversation

@proski
Copy link
Copy Markdown

@proski proski commented Apr 8, 2026

Motivation

The enqueueFileTransfer function needs refactoring, even more so after PR #348.

This PR (just one commit) should be added to PR #348.

Context

I tried to add the change as a suggestion, but the result did not look good in github GUI. So I'm making it a PR.

Summary by CodeRabbit

No user-facing changes in this release. This update includes internal refactoring of file transfer handling to improve code maintainability.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 8, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3c22f696-fc35-4ee7-9a40-4f92976d5669

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Refactored S3 request handling in curlFileTransfer by extracting a new makeTransferItem() helper function that constructs transfer items with S3-specific setup. Separated item construction logic from enqueue error handling, which is now consolidated in the enqueueFileTransfer() method.

Changes

Cohort / File(s) Summary
S3 Request Refactoring
src/libstore/filetransfer.cc
Extracted inline S3-specific TransferItem construction logic into a new makeTransferItem() helper function; moved enqueue and exception handling from item creation context into the enqueueFileTransfer() method for centralized error handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • edolstra

Poem

🐰 A helper born from tangled code so deep,
Where S3 flows now orderly and neat,
Errors caught where enqueues dare to creep,
Logic split with purpose, clear and sweet! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title 'Refactor enqueueFileTransfer' directly describes the main refactoring performed: extracting a makeTransferItem helper and reorganizing the enqueueFileTransfer function.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@proski proski marked this pull request as draft April 8, 2026 21:45
@proski proski force-pushed the refactor-enqueueFileTransfer branch from 85e1dd9 to 9dd7d67 Compare April 8, 2026 21:52
@proski proski marked this pull request as ready for review April 8, 2026 21:53
@proski
Copy link
Copy Markdown
Author

proski commented Apr 8, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 8, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@proski proski changed the title Refactor enqueue file transfer Refactor enqueueFileTransfer Apr 8, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/libstore/filetransfer.cc`:
- Around line 975-991: Remove the noexcept from makeTransferItem so exceptions
from setupForS3() and make_ref<TransferItem>() can propagate into the existing
error-handling in enqueueFileTransfer; update the declaration of
makeTransferItem (the function that calls setupForS3() and returns
make_ref<TransferItem>) to be non-noexcept so thrown BadURL or parsing
exceptions are caught by the try/catch around the call in enqueueFileTransfer
and translated via item->fail(e).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 82d9f7de-67d7-4752-a652-c9a12c9f1d82

📥 Commits

Reviewing files that changed from the base of the PR and between b69b84e and 9dd7d67.

📒 Files selected for processing (1)
  • src/libstore/filetransfer.cc

Comment on lines +975 to +991
inline ref<TransferItem>
makeTransferItem(const FileTransferRequest & request, Callback<FileTransferResult> callback) noexcept
{
/* Handle s3:// URIs by converting to HTTPS and optionally adding auth */
if (request.uri.scheme() == "s3") {
auto modifiedRequest = request;
modifiedRequest.setupForS3();
auto item = make_ref<TransferItem>(*this, std::move(modifiedRequest), std::move(callback));
try {
return enqueueItem(item);
} catch (const nix::BaseError & e) {
// NOTE(cole-h): catches both nix::Error and nix::Interrupted -- enqueueItem calls
// writeFull which may throw nix::Interrupted, and the rest of enqueueItem may throw
// nix::Error
item->fail(e);
return ItemHandle(item.get_ptr());
}
return make_ref<TransferItem>(*this, std::move(modifiedRequest), std::move(callback));
} else {
return make_ref<TransferItem>(*this, request, std::move(callback));
}
}

ItemHandle
enqueueFileTransfer(const FileTransferRequest & request, Callback<FileTransferResult> callback) noexcept override
{
const auto item = makeTransferItem(request, std::move(callback));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

cat -n src/libstore/filetransfer.cc | sed -n '970,1010p'

Repository: DeterminateSystems/nix-src

Length of output: 1870


🏁 Script executed:

rg -A 10 "void setupForS3" src/libstore/filetransfer.cc

Repository: DeterminateSystems/nix-src

Length of output: 52


🏁 Script executed:

rg "try\s*{" src/libstore/filetransfer.cc | head -20

Repository: DeterminateSystems/nix-src

Length of output: 147


🏁 Script executed:

rg "setupForS3" src/libstore/filetransfer.cc -B 2 -A 15

Repository: DeterminateSystems/nix-src

Length of output: 1544


🏁 Script executed:

rg "class TransferItem" src/libstore/filetransfer.cc -A 30

Repository: DeterminateSystems/nix-src

Length of output: 52


🏁 Script executed:

rg "make_ref" include/ -t cpp --max-count=5

Repository: DeterminateSystems/nix-src

Length of output: 118


🏁 Script executed:

rg "ParsedS3URL::parse" src/ -B 2 -A 10

Repository: DeterminateSystems/nix-src

Length of output: 5572


🏁 Script executed:

rg "struct TransferItem" src/libstore/filetransfer.cc -A 25

Repository: DeterminateSystems/nix-src

Length of output: 1143


🏁 Script executed:

rg "TransferItem\(" src/libstore/filetransfer.cc -B 2 -A 5 | head -40

Repository: DeterminateSystems/nix-src

Length of output: 1283


🏁 Script executed:

rg "TransferItem::" src/libstore/filetransfer.cc -A 20 | grep -A 20 "TransferItem("

Repository: DeterminateSystems/nix-src

Length of output: 52


🏁 Script executed:

rg "noexcept" src/libstore/filetransfer.cc | grep -i "transfer"

Repository: DeterminateSystems/nix-src

Length of output: 405


Remove noexcept from makeTransferItem() to allow proper error handling.

Line 976 marks makeTransferItem() as noexcept, but it calls setupForS3() and make_ref<TransferItem>(), both of which can throw. The setupForS3() method calls ParsedS3URL::parse(), which throws BadURL and other parsing exceptions. Since makeTransferItem() is invoked on line 991 before the try block (line 993), any of these exceptions will trigger std::terminate instead of being caught and translated into a failed transfer callback via item->fail(e). Remove the noexcept qualifier and ensure item construction is covered by the existing error-handling path.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/libstore/filetransfer.cc` around lines 975 - 991, Remove the noexcept
from makeTransferItem so exceptions from setupForS3() and
make_ref<TransferItem>() can propagate into the existing error-handling in
enqueueFileTransfer; update the declaration of makeTransferItem (the function
that calls setupForS3() and returns make_ref<TransferItem>) to be non-noexcept
so thrown BadURL or parsing exceptions are caught by the try/catch around the
call in enqueueFileTransfer and translated via item->fail(e).

@proski proski force-pushed the refactor-enqueueFileTransfer branch from 9dd7d67 to b0abc42 Compare April 10, 2026 18:55
@proski
Copy link
Copy Markdown
Author

proski commented Apr 10, 2026

Removed noexcept as requested. That was a very good catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant