From cda4cd2a73ce6b9dfb27d8e1bec61005ca4e6195 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 7 Oct 2026 09:21:07 -0500 Subject: guard clauses and docs --- src/slskd/Transfers/Uploads/UploadQueue.cs | 38 +++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/slskd/Transfers/Uploads/UploadQueue.cs b/src/slskd/Transfers/Uploads/UploadQueue.cs index de5a613d..6e7e73df 100644 --- a/src/slskd/Transfers/Uploads/UploadQueue.cs +++ b/src/slskd/Transfers/Uploads/UploadQueue.cs @@ -52,29 +52,33 @@ namespace slskd.Transfers.Uploads /// /// Awaits the start of an upload by returning a that is completed when the queue initiates it. /// - /// The transfer to await. + /// The Transfer to await. /// The token to monitor for cancellation requests. /// The operation context. + /// Thrown if the specified Transfer is null. Task AwaitStartAsync(Transfer transfer, CancellationToken cancellationToken = default); /// /// Signals the completion of an upload. /// - /// The transfer to complete. + /// The Transfer to complete. + /// Thrown if the specified Transfer is null. void Complete(Transfer transfer); /// /// Gracefully attempts to signal the completion of an upload, returning false if a problem is encountered /// (such as the upload not being tracked currently). /// - /// The transfer to complete. - /// A value indicating whether a problem was encountered. + /// The Transfer to complete. + /// A value indicating whether a problem was encountered. + /// Thrown if the specified Transfer is null. bool TryComplete(Transfer transfer); /// /// Enqueues an upload. /// - /// The upload to enqueue. + /// The Transfer to enqueue. + /// Thrown if the specified Transfer is null. void Enqueue(Transfer transfer); /// @@ -104,6 +108,7 @@ namespace slskd.Transfers.Uploads /// /// The user's group, the group's total and free slots, and the estimated position if the user were to enqueue a file. /// + /// Thrown if the specified username is null or consists only of whitespace. (string Group, int TotalSlots, int FreeSlots, int Position) ForecastPosition(string username); } @@ -142,11 +147,14 @@ namespace slskd.Transfers.Uploads /// /// Awaits the start of an upload by returning a that is completed when the queue initiates it. /// - /// The transfer to await. + /// The Transfer to await. /// The token to monitor for cancellation requests. /// The operation context. + /// Thrown if the specified Transfer is null. public Task AwaitStartAsync(Transfer transfer, CancellationToken cancellationToken = default) { + ArgumentNullException.ThrowIfNull(transfer); + SyncRoot.Wait(cancellationToken); try @@ -179,10 +187,13 @@ namespace slskd.Transfers.Uploads /// Gracefully attempts to signal the completion of an upload, returning false if a problem is encountered /// (such as the upload not being tracked currently). /// - /// The transfer to complete. + /// The Transfer to complete. /// A value indicating whether a problem was encountered. + /// Thrown if the specified Transfer is null. public bool TryComplete(Transfer transfer) { + ArgumentNullException.ThrowIfNull(transfer); + try { Complete(transfer); @@ -197,9 +208,12 @@ namespace slskd.Transfers.Uploads /// /// Signals the completion of an upload. /// - /// The transfer to complete. + /// The Transfer to complete. + /// Thrown if the specified Transfer is null. public void Complete(Transfer transfer) { + ArgumentNullException.ThrowIfNull(transfer); + SyncRoot.Wait(); try @@ -254,9 +268,12 @@ namespace slskd.Transfers.Uploads /// /// Enqueues an upload. /// - /// The upload to enqueue. + /// The Transfer to enqueue. + /// Thrown if the specified Transfer is null. public void Enqueue(Transfer transfer) { + ArgumentNullException.ThrowIfNull(transfer); + SyncRoot.Wait(); try @@ -404,8 +421,11 @@ namespace slskd.Transfers.Uploads /// /// The user's group, the group's total and free slots, and the estimated position if the user were to enqueue a file. /// + /// Thrown if the specified username is null or consists only of whitespace. public (string Group, int TotalSlots, int FreeSlots, int Position) ForecastPosition(string username) { + ArgumentException.ThrowIfNullOrWhiteSpace(username); + var groupName = Users.GetGroup(username); if (!Groups.TryGetValue(groupName, out var groupRecord)) -- cgit v1.2.3