chore(config): tighten download thread limits#161
Open
Craun718 wants to merge 2 commits into
Open
Conversation
|
@Craun718 is attempting to deploy a commit to the retrofor Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideTightens and enforces bounds on the launcher’s download thread configuration across backend config loading/saving and the UI schema, while lowering the default value and normalizing saved configs. Sequence diagram for saving config with sanitization and normalizationsequenceDiagram
participant UiConfigEditor
participant TauriMain as save_raw_config
participant LauncherConfig
participant SerdeJson as serde_json
participant TokioFs as tokio_fs
UiConfigEditor->>TauriMain: save_raw_config(state, content)
TauriMain->>SerdeJson: from_str(content)
SerdeJson-->>TauriMain: LauncherConfig
TauriMain->>LauncherConfig: sanitize()
TauriMain->>SerdeJson: to_string_pretty(LauncherConfig)
SerdeJson-->>TauriMain: normalized_content
TauriMain->>TokioFs: write(state.file_path, normalized_content)
TokioFs-->>TauriMain: Result
TauriMain-->>UiConfigEditor: Result
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src-tauri/src/core/config.rs" line_range="130" />
<code_context>
+impl LauncherConfig {
+ pub fn sanitize(&mut self) {
+ self.download_threads = self.download_threads.clamp(1, 64);
+ }
+}
</code_context>
<issue_to_address>
**suggestion:** Avoid hardcoding the download thread bounds directly in sanitize to keep limits consistent across the codebase.
The 1 and 64 bounds are duplicated here, in the doc comment, and in the UI schema. Consider defining shared constants (e.g., `MIN_DOWNLOAD_THREADS` / `MAX_DOWNLOAD_THREADS`) and reusing them in `sanitize()` and any related logic to keep these limits consistent and easier to update.
Suggested implementation:
```rust
pub const MIN_DOWNLOAD_THREADS: usize = 1;
pub const MAX_DOWNLOAD_THREADS: usize = 64;
impl LauncherConfig {
pub fn sanitize(&mut self) {
self.download_threads = self
.download_threads
.clamp(MIN_DOWNLOAD_THREADS, MAX_DOWNLOAD_THREADS);
}
}
```
```rust
```
To fully apply the suggestion across the codebase, also:
1. Update the doc comment that describes the valid range for `download_threads` to reference `MIN_DOWNLOAD_THREADS` and `MAX_DOWNLOAD_THREADS` (or ensure the text stays in sync with these values).
2. Update any UI schema or validation logic that currently hardcodes `1` and `64` for download thread bounds to instead use these shared constants, or otherwise centralize those limits so they derive from `MIN_DOWNLOAD_THREADS` and `MAX_DOWNLOAD_THREADS`.
</issue_to_address>
### Comment 2
<location path="src-tauri/src/main.rs" line_range="1653-1654" />
<code_context>
serde_json::from_str(&content).map_err(|e| format!("Invalid JSON: {}", e))?;
+ new_config.sanitize();
+
+ let normalized_content =
+ serde_json::to_string_pretty(&new_config).map_err(|e| format!("Invalid JSON: {}", e))?;
// Save to file
</code_context>
<issue_to_address>
**suggestion:** Use a more accurate error message when serialization of the config fails.
`map_err(|e| format!("Invalid JSON: {}", e))` is appropriate for `from_str`, but misleading for `to_string_pretty` since the JSON is already valid at that point. Use a different message (e.g. `"Failed to serialize config"`) so callers can distinguish parse errors from serialization failures.
```suggestion
let normalized_content = serde_json::to_string_pretty(&new_config)
.map_err(|e| format!("Failed to serialize config: {}", e))?;
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Tighten and enforce limits on the launcher download thread configuration and ensure configs are sanitized on load and save.
Enhancements: