refactored: review findings - style and abstraction cleanup
- drop stale phase planning comments from launch_profile module headers. - simplify merge_libraries to HashSet<&str> (no string clones). - rewrite coord_key with match_indices (clearer intent). - read /proc/sys/kernel/osrelease on linux for mojang_os_version instead of shelling out to uname; return empty elsewhere. - add comment explaining why is_retryable excludes Parse. - shorten the launch_profile::... paths in launch/mod.rs with top-level use statements. - derive Default on LaunchProfile + nested types so test fixtures use ..Default::default() instead of listing every None field. - inline account_can_launch at its single call site, delete the helper and three tests that exercised trivially-correct one-line logic. - extract get_json_with_raw on HttpClient and save_profile_bytes in instance::loader; collapses three near-identical fetch_X_profile_with_raw helpers and three near-identical 'create dir + write bytes' blocks.
This commit is contained in:
1 parent
412e6ff91a
commit
363ada8211
15 files changed
+155
-292
No files matched your search
+19
-1
@@ -80,6 +80,21 @@ impl HttpClient {
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
// fetch JSON and also keep the raw bytes. used by install paths that
|
||||
// want both the parsed shape (for downloading libraries from it) and
|
||||
// the original bytes (to write byte-for-byte to the loader-profiles
|
||||
// cache, so any field we don't know about survives).
|
||||
pub async fn get_json_with_raw<T: DeserializeOwned>(
|
||||
&self,
|
||||
url: &str,
|
||||
label: &str,
|
||||
) -> Result<(T, Vec<u8>), NetError> {
|
||||
let raw = self.get_bytes(url).await?;
|
||||
let parsed: T = serde_json::from_slice(&raw)
|
||||
.map_err(|e| NetError::Parse(format!("Failed to parse {label}: {e}")))?;
|
||||
Ok((parsed, raw))
|
||||
}
|
||||
}
|
||||
|
||||
// shared retry envelope around `client.get(url).await? -> decode`. retries
|
||||
@@ -183,7 +198,10 @@ async fn download_file_once(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// body decode errors and timeouts are worth retrying, but a 404 or disk error isn't
|
||||
// body decode errors and timeouts are worth retrying, but a 404 or disk
|
||||
// error isn't. Parse errors stay non-retryable: by the time we hit one
|
||||
// the response body has fully arrived, so the failure means the upstream
|
||||
// returned malformed JSON - retrying won't fix that.
|
||||
fn is_retryable(err: &NetError) -> bool {
|
||||
match err {
|
||||
NetError::Http(e) => e.is_timeout() || e.is_body() || e.is_connect(),
|
||||
|
||||
Reference in new issue
Block a user