Skip to content

Commit b5cc0cc

Browse files
hyperpolymathclaude
andcommitted
Revert 58 .expect("TODO: handle error") sites in ffi/rust/src/ (batch 8/N)
Final batch. Sweeps the now-canonical Rust FFI tree (the duplicate impl/rust-ffi/ was deleted in commit f43cfb5). All 58 sites are inside `#[cfg(test)] mod tests` blocks across 7 files: audit.rs (11), lib.rs (14), operations.rs (17), preconditions.rs (5), rmo.rs (6), sandbox.rs (3), verification.rs (2). Per-site policy: mass replace_all to .unwrap() — entirely test scaffolding (tempdir setup, FfiContext::new, file write/read/delete operation chains in test_*_operation tests, secure_delete tests, path resolution tests, verification suite tests). All preceding input-controlled or assert!()-proven Some/Ok cases. Verified locally: cargo build -> EXIT 0 (warnings unchanged) cargo test -> 24 passed / 0 failed / 0 ignored Cumulative progress across batches 1-8: * impl/rust-cli/src/ : 404 sites cleared (audit headline figure) * ffi/rust/src/ : 58 sites cleared (this batch) * impl/rust-ffi/ : tree deleted, ~50 sites removed by deletion * Total : ~512 sites cleared / ~530 originally found (~96.6%); residue is zero in source code. Estate-wide grep for `.expect("TODO: handle error")` across the repo now returns hits only in documentation files (CRG-AUDIT-2026-04-18.adoc + ROADMAP.adoc) where the string is quoted as a historical reference, not invoked. The .expect("TODO: handle error") anti-pattern is now retired from the valence-shell code surface. Item 1 of the CRG-AUDIT-2026-04-18 closure list is closed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f43cfb5 commit b5cc0cc

7 files changed

Lines changed: 58 additions & 58 deletions

File tree

ffi/rust/src/audit.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -264,31 +264,31 @@ mod tests {
264264

265265
#[test]
266266
fn test_audit_log_creation() {
267-
let tmp = tempdir().expect("TODO: handle error");
267+
let tmp = tempdir().unwrap();
268268
let path = tmp.path().join("audit.jsonl");
269269

270-
let mut log = AuditLog::new(path.clone()).expect("TODO: handle error");
270+
let mut log = AuditLog::new(path.clone()).unwrap();
271271

272-
log.log_operation("mkdir", "/test/dir", None).expect("TODO: handle error");
273-
log.log_operation("touch", "/test/file.txt", Some(0)).expect("TODO: handle error");
272+
log.log_operation("mkdir", "/test/dir", None).unwrap();
273+
log.log_operation("touch", "/test/file.txt", Some(0)).unwrap();
274274

275275
assert_eq!(log.entry_count(), 2);
276276
}
277277

278278
#[test]
279279
fn test_audit_log_integrity() {
280-
let tmp = tempdir().expect("TODO: handle error");
280+
let tmp = tempdir().unwrap();
281281
let path = tmp.path().join("audit.jsonl");
282282

283283
{
284-
let mut log = AuditLog::new(path.clone()).expect("TODO: handle error");
285-
log.log_operation("mkdir", "/a", None).expect("TODO: handle error");
286-
log.log_operation("mkdir", "/b", None).expect("TODO: handle error");
287-
log.log_operation("rmdir", "/a", None).expect("TODO: handle error");
284+
let mut log = AuditLog::new(path.clone()).unwrap();
285+
log.log_operation("mkdir", "/a", None).unwrap();
286+
log.log_operation("mkdir", "/b", None).unwrap();
287+
log.log_operation("rmdir", "/a", None).unwrap();
288288
}
289289

290290
// Verify integrity
291-
let log = AuditLog::new(path).expect("TODO: handle error");
292-
assert!(log.verify_integrity().expect("TODO: handle error"));
291+
let log = AuditLog::new(path).unwrap();
292+
assert!(log.verify_integrity().unwrap());
293293
}
294294
}

ffi/rust/src/lib.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -381,63 +381,63 @@ mod tests {
381381

382382
#[test]
383383
fn test_mkdir_rmdir_reversible() {
384-
let tmp = tempdir().expect("TODO: handle error");
384+
let tmp = tempdir().unwrap();
385385
let config = FfiConfig {
386386
sandbox_root: tmp.path().to_path_buf(),
387387
..Default::default()
388388
};
389389

390-
let mut ctx = FfiContext::new(config).expect("TODO: handle error");
390+
let mut ctx = FfiContext::new(config).unwrap();
391391

392392
// mkdir
393-
ctx.mkdir("test_dir").expect("TODO: handle error");
393+
ctx.mkdir("test_dir").unwrap();
394394
assert!(tmp.path().join("test_dir").exists());
395395

396396
// rmdir (reverse)
397-
ctx.rmdir("test_dir").expect("TODO: handle error");
397+
ctx.rmdir("test_dir").unwrap();
398398
assert!(!tmp.path().join("test_dir").exists());
399399
}
400400

401401
#[test]
402402
fn test_create_delete_file_reversible() {
403-
let tmp = tempdir().expect("TODO: handle error");
403+
let tmp = tempdir().unwrap();
404404
let config = FfiConfig {
405405
sandbox_root: tmp.path().to_path_buf(),
406406
..Default::default()
407407
};
408408

409-
let mut ctx = FfiContext::new(config).expect("TODO: handle error");
409+
let mut ctx = FfiContext::new(config).unwrap();
410410

411411
// create_file
412-
ctx.create_file("test.txt").expect("TODO: handle error");
412+
ctx.create_file("test.txt").unwrap();
413413
assert!(tmp.path().join("test.txt").exists());
414414

415415
// delete_file (reverse)
416-
ctx.delete_file("test.txt").expect("TODO: handle error");
416+
ctx.delete_file("test.txt").unwrap();
417417
assert!(!tmp.path().join("test.txt").exists());
418418
}
419419

420420
#[test]
421421
fn test_write_file_reversible() {
422-
let tmp = tempdir().expect("TODO: handle error");
422+
let tmp = tempdir().unwrap();
423423
let config = FfiConfig {
424424
sandbox_root: tmp.path().to_path_buf(),
425425
..Default::default()
426426
};
427427

428-
let mut ctx = FfiContext::new(config).expect("TODO: handle error");
428+
let mut ctx = FfiContext::new(config).unwrap();
429429

430430
// Create file first
431-
ctx.create_file("test.txt").expect("TODO: handle error");
431+
ctx.create_file("test.txt").unwrap();
432432

433433
// Write new content, get old
434-
let old = ctx.write_file("test.txt", b"new content").expect("TODO: handle error");
434+
let old = ctx.write_file("test.txt", b"new content").unwrap();
435435
assert_eq!(old, b"");
436436

437437
// Write old content back (reverse)
438-
ctx.write_file("test.txt", &old).expect("TODO: handle error");
438+
ctx.write_file("test.txt", &old).unwrap();
439439

440-
let content = ctx.read_file("test.txt").expect("TODO: handle error");
440+
let content = ctx.read_file("test.txt").unwrap();
441441
assert_eq!(content, b"");
442442
}
443443
}

ffi/rust/src/operations.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -456,54 +456,54 @@ mod tests {
456456

457457
#[test]
458458
fn test_file_type_detection() {
459-
let tmp = tempdir().expect("TODO: handle error");
459+
let tmp = tempdir().unwrap();
460460

461461
// Create file
462462
let file_path = tmp.path().join("test.txt");
463-
fs::write(&file_path, "content").expect("TODO: handle error");
463+
fs::write(&file_path, "content").unwrap();
464464

465-
let info = FileInfo::from_path(&file_path).expect("TODO: handle error");
465+
let info = FileInfo::from_path(&file_path).unwrap();
466466
assert_eq!(info.file_type, FileType::RegularFile);
467467

468468
// Create directory
469469
let dir_path = tmp.path().join("subdir");
470-
fs::create_dir(&dir_path).expect("TODO: handle error");
470+
fs::create_dir(&dir_path).unwrap();
471471

472-
let info = FileInfo::from_path(&dir_path).expect("TODO: handle error");
472+
let info = FileInfo::from_path(&dir_path).unwrap();
473473
assert_eq!(info.file_type, FileType::Directory);
474474
}
475475

476476
#[test]
477477
fn test_list_directory() {
478-
let tmp = tempdir().expect("TODO: handle error");
478+
let tmp = tempdir().unwrap();
479479

480-
fs::write(tmp.path().join("a.txt"), "").expect("TODO: handle error");
481-
fs::write(tmp.path().join("b.txt"), "").expect("TODO: handle error");
482-
fs::create_dir(tmp.path().join("subdir")).expect("TODO: handle error");
480+
fs::write(tmp.path().join("a.txt"), "").unwrap();
481+
fs::write(tmp.path().join("b.txt"), "").unwrap();
482+
fs::create_dir(tmp.path().join("subdir")).unwrap();
483483

484-
let entries = list_directory(tmp.path()).expect("TODO: handle error");
484+
let entries = list_directory(tmp.path()).unwrap();
485485
assert_eq!(entries.len(), 3);
486486
}
487487

488488
#[test]
489489
fn test_atomic_write() {
490-
let tmp = tempdir().expect("TODO: handle error");
490+
let tmp = tempdir().unwrap();
491491
let path = tmp.path().join("atomic.txt");
492492

493-
atomic_write(&path, b"test content").expect("TODO: handle error");
493+
atomic_write(&path, b"test content").unwrap();
494494

495495
assert!(path.exists());
496-
assert_eq!(fs::read_to_string(&path).expect("TODO: handle error"), "test content");
496+
assert_eq!(fs::read_to_string(&path).unwrap(), "test content");
497497
}
498498

499499
#[test]
500500
fn test_directory_size() {
501-
let tmp = tempdir().expect("TODO: handle error");
501+
let tmp = tempdir().unwrap();
502502

503-
fs::write(tmp.path().join("a.txt"), "12345").expect("TODO: handle error");
504-
fs::write(tmp.path().join("b.txt"), "123").expect("TODO: handle error");
503+
fs::write(tmp.path().join("a.txt"), "12345").unwrap();
504+
fs::write(tmp.path().join("b.txt"), "123").unwrap();
505505

506-
let size = directory_size(tmp.path()).expect("TODO: handle error");
506+
let size = directory_size(tmp.path()).unwrap();
507507
assert_eq!(size, 8);
508508
}
509509
}

ffi/rust/src/preconditions.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,14 @@ mod tests {
407407

408408
#[test]
409409
fn test_mkdir_preconditions() {
410-
let tmp = tempdir().expect("TODO: handle error");
410+
let tmp = tempdir().unwrap();
411411
let path = tmp.path().join("new_dir");
412412

413413
// Should succeed - path doesn't exist, parent exists
414414
assert!(Preconditions::mkdir(&path).is_ok());
415415

416416
// Create it
417-
fs::create_dir(&path).expect("TODO: handle error");
417+
fs::create_dir(&path).unwrap();
418418

419419
// Should fail - path exists
420420
assert!(matches!(
@@ -425,7 +425,7 @@ mod tests {
425425

426426
#[test]
427427
fn test_rmdir_preconditions() {
428-
let tmp = tempdir().expect("TODO: handle error");
428+
let tmp = tempdir().unwrap();
429429
let path = tmp.path().join("dir_to_remove");
430430

431431
// Should fail - doesn't exist
@@ -435,13 +435,13 @@ mod tests {
435435
));
436436

437437
// Create empty directory
438-
fs::create_dir(&path).expect("TODO: handle error");
438+
fs::create_dir(&path).unwrap();
439439

440440
// Should succeed
441441
assert!(Preconditions::rmdir(&path).is_ok());
442442

443443
// Add a file
444-
fs::write(path.join("file.txt"), "content").expect("TODO: handle error");
444+
fs::write(path.join("file.txt"), "content").unwrap();
445445

446446
// Should fail - not empty
447447
assert!(matches!(

ffi/rust/src/rmo.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,31 +357,31 @@ mod tests {
357357

358358
#[test]
359359
fn test_secure_delete_file() {
360-
let tmp = tempdir().expect("TODO: handle error");
360+
let tmp = tempdir().unwrap();
361361
let file_path = tmp.path().join("test_file.txt");
362362

363363
// Create test file
364-
std::fs::write(&file_path, "sensitive data here").expect("TODO: handle error");
364+
std::fs::write(&file_path, "sensitive data here").unwrap();
365365
assert!(file_path.exists());
366366

367367
// Secure delete
368-
secure_delete(&file_path, 3).expect("TODO: handle error");
368+
secure_delete(&file_path, 3).unwrap();
369369

370370
// File should be gone
371371
assert!(!file_path.exists());
372372
}
373373

374374
#[test]
375375
fn test_secure_delete_empty_file() {
376-
let tmp = tempdir().expect("TODO: handle error");
376+
let tmp = tempdir().unwrap();
377377
let file_path = tmp.path().join("empty.txt");
378378

379379
// Create empty file
380-
std::fs::write(&file_path, "").expect("TODO: handle error");
380+
std::fs::write(&file_path, "").unwrap();
381381
assert!(file_path.exists());
382382

383383
// Secure delete
384-
secure_delete(&file_path, 3).expect("TODO: handle error");
384+
secure_delete(&file_path, 3).unwrap();
385385

386386
// File should be gone
387387
assert!(!file_path.exists());

ffi/rust/src/sandbox.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,14 @@ mod tests {
229229
#[test]
230230
fn test_resolve_simple_path() {
231231
let sandbox = PathBuf::from("/tmp/sandbox");
232-
let resolved = resolve_path(&sandbox, "foo/bar").expect("TODO: handle error");
232+
let resolved = resolve_path(&sandbox, "foo/bar").unwrap();
233233
assert_eq!(resolved, PathBuf::from("/tmp/sandbox/foo/bar"));
234234
}
235235

236236
#[test]
237237
fn test_resolve_absolute_path() {
238238
let sandbox = PathBuf::from("/tmp/sandbox");
239-
let resolved = resolve_path(&sandbox, "/foo/bar").expect("TODO: handle error");
239+
let resolved = resolve_path(&sandbox, "/foo/bar").unwrap();
240240
assert_eq!(resolved, PathBuf::from("/tmp/sandbox/foo/bar"));
241241
}
242242

@@ -250,7 +250,7 @@ mod tests {
250250
#[test]
251251
fn test_normalize_parent() {
252252
let sandbox = PathBuf::from("/tmp/sandbox");
253-
let resolved = resolve_path(&sandbox, "foo/../bar").expect("TODO: handle error");
253+
let resolved = resolve_path(&sandbox, "foo/../bar").unwrap();
254254
assert_eq!(resolved, PathBuf::from("/tmp/sandbox/bar"));
255255
}
256256

ffi/rust/src/verification.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ mod tests {
444444

445445
#[test]
446446
fn test_verification_suite() {
447-
let suite = VerificationSuite::new().expect("TODO: handle error");
448-
let results = suite.run_all().expect("TODO: handle error");
447+
let suite = VerificationSuite::new().unwrap();
448+
let results = suite.run_all().unwrap();
449449

450450
for result in &results {
451451
if !result.passed {

0 commit comments

Comments
 (0)