Skip to content

Commit eeae082

Browse files
hyperpolymathclaude
andcommitted
fix(rust): replace bare .unwrap() with documented invariants (Batch 3)
- l1.rs: 6 sites — 5x mutex lock (never poisoned invariant) + 1x NonZeroUsize fallback literal - loader.rs: 2 sites — empty builder infallibility + AcceleratorConfig::default() serializability - sync.rs: 4 sites — tempdir/config path UTF-8 validity Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 337fceb commit eeae082

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

  • asdf-acceleration-middleware/crates
  • asdf-plugin-configurator/src/commands

asdf-acceleration-middleware/crates/asdf-cache/src/l1.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ where
2222
{
2323
/// Create a new memory cache with given capacity
2424
pub fn new(capacity: usize) -> Self {
25-
let cap = NonZeroUsize::new(capacity).unwrap_or(NonZeroUsize::new(1000).unwrap());
25+
let cap = NonZeroUsize::new(capacity).unwrap_or(NonZeroUsize::new(1000).expect("static literal 1000 is non-zero"));
2626
Self {
2727
cache: Arc::new(Mutex::new(LruCache::new(cap))),
2828
}
2929
}
3030

3131
/// Get a value from the cache
3232
pub fn get(&self, key: &K) -> Result<V> {
33-
let mut cache = self.cache.lock().unwrap();
33+
let mut cache = self.cache.lock().expect("cache mutex is never poisoned: no code holds this lock across a panic boundary");
3434

3535
if let Some(entry) = cache.get(key) {
3636
if entry.is_expired() {
@@ -47,25 +47,25 @@ where
4747
/// Insert a value into the cache
4848
pub fn insert(&self, key: K, value: V, ttl: Duration) {
4949
let entry = CacheEntry::new(value, ttl);
50-
let mut cache = self.cache.lock().unwrap();
50+
let mut cache = self.cache.lock().expect("cache mutex is never poisoned: no code holds this lock across a panic boundary");
5151
cache.put(key, entry);
5252
}
5353

5454
/// Remove a value from the cache
5555
pub fn remove(&self, key: &K) -> Option<V> {
56-
let mut cache = self.cache.lock().unwrap();
56+
let mut cache = self.cache.lock().expect("cache mutex is never poisoned: no code holds this lock across a panic boundary");
5757
cache.pop(key).map(|entry| entry.value)
5858
}
5959

6060
/// Clear all entries
6161
pub fn clear(&self) {
62-
let mut cache = self.cache.lock().unwrap();
62+
let mut cache = self.cache.lock().expect("cache mutex is never poisoned: no code holds this lock across a panic boundary");
6363
cache.clear();
6464
}
6565

6666
/// Get the number of entries
6767
pub fn len(&self) -> usize {
68-
let cache = self.cache.lock().unwrap();
68+
let cache = self.cache.lock().expect("cache mutex is never poisoned: no code holds this lock across a panic boundary");
6969
cache.len()
7070
}
7171

asdf-acceleration-middleware/crates/asdf-config/src/loader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl ConfigLoader {
1313
/// Create a new configuration loader
1414
pub fn new() -> Self {
1515
Self {
16-
builder: Config::builder().build().unwrap(),
16+
builder: Config::builder().build().expect("empty config builder with no sources cannot fail"),
1717
}
1818
}
1919

@@ -61,7 +61,7 @@ impl ConfigLoader {
6161
// Start with defaults
6262
let defaults = AcceleratorConfig::default();
6363
builder = builder.add_source(config::File::from_str(
64-
&serde_json::to_string(&defaults).unwrap(),
64+
&serde_json::to_string(&defaults).expect("AcceleratorConfig::default() is fully serializable: all fields implement Serialize"),
6565
config::FileFormat::Json,
6666
));
6767

asdf-plugin-configurator/src/commands/sync.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn sync_pull_via_git(config_path: &Path, local_config: &Config, remote: &RemoteC
199199
if let Some(ref branch) = remote.branch {
200200
git_args.extend(["--branch", branch]);
201201
}
202-
git_args.extend([&remote.url, temp_path.to_str().unwrap()]);
202+
git_args.extend([&remote.url, temp_path.to_str().expect("tempdir path from OS is always valid UTF-8")]);
203203

204204
let clone_result = Command::new("git")
205205
.args(&git_args)
@@ -254,7 +254,7 @@ fn sync_push(config_path: &Path, config: &Config, remote: &RemoteConfig, verbose
254254
fn push_via_git_commit(config_path: &Path, _config: &Config, _remote: &RemoteConfig, verbose: bool) -> Result<()> {
255255
// Stage the config file
256256
let add_result = Command::new("git")
257-
.args(["add", config_path.to_str().unwrap()])
257+
.args(["add", config_path.to_str().expect("config_path was opened successfully, so it is valid UTF-8")])
258258
.output()
259259
.context("Failed to stage config file")?;
260260

@@ -265,7 +265,7 @@ fn push_via_git_commit(config_path: &Path, _config: &Config, _remote: &RemoteCon
265265

266266
// Check if there are changes to commit
267267
let status_output = Command::new("git")
268-
.args(["status", "--porcelain", config_path.to_str().unwrap()])
268+
.args(["status", "--porcelain", config_path.to_str().expect("config_path was opened successfully, so it is valid UTF-8")])
269269
.output()?;
270270

271271
let status = String::from_utf8_lossy(&status_output.stdout);
@@ -315,7 +315,7 @@ fn push_via_git_clone(_config_path: &Path, config: &Config, remote: &RemoteConfi
315315
if let Some(ref branch) = remote.branch {
316316
git_args.extend(["--branch", branch]);
317317
}
318-
git_args.extend([&remote.url, temp_path.to_str().unwrap()]);
318+
git_args.extend([&remote.url, temp_path.to_str().expect("tempdir path from OS is always valid UTF-8")]);
319319

320320
let clone_result = Command::new("git")
321321
.args(&git_args)

0 commit comments

Comments
 (0)