Skip to content

Commit a0b0bdd

Browse files
hyperpolymathclaude
andcommitted
fix(januskey): sweep .expect("TODO: handle error") — 166 sites cleared
Replaced all 166 occurrences of .expect("TODO: handle error") across januskey and its subcomponents with context-appropriate error handling: - 161 test sites: converted to .unwrap() (test convention) - 3 true invariants: documented with explanatory .expect() messages * progress bar template (compile-time guaranteed) * mutex post-push guarantee - 2 production error propagation: replaced with Result error handling * current directory fallback in main() * graceful context propagation Cryptographic key operations preserved without silent panics. Tests: 24 unit tests passed (januskey lib) 12 unit tests passed (reversible-core lib) 8 integration tests passed (jk-keys) Build: cargo check passes cleanly Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 21c7658 commit a0b0bdd

17 files changed

Lines changed: 172 additions & 166 deletions

File tree

crates/januskey-cli/src/delta.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,15 +466,15 @@ mod tests {
466466

467467
let delta = Delta::compute(original, new);
468468
assert!(delta.is_full());
469-
assert_eq!(delta.apply(original).expect("TODO: handle error"), new.to_vec());
469+
assert_eq!(delta.apply(original).unwrap(), new.to_vec());
470470
}
471471

472472
#[test]
473473
fn test_line_diff() {
474474
let original = b"line 1\nline 2\nline 3\nline 4\nline 5\n".repeat(100);
475475
let new = original.clone();
476476
// Modify line 50
477-
let new_str = String::from_utf8(new.clone()).expect("TODO: handle error");
477+
let new_str = String::from_utf8(new.clone()).unwrap();
478478
let lines: Vec<&str> = new_str.lines().collect();
479479
let mut new_lines = lines.clone();
480480
new_lines[49] = "modified line 50";
@@ -488,7 +488,7 @@ mod tests {
488488
}
489489

490490
// Applying delta should produce new content
491-
let restored = delta.apply(&original).expect("TODO: handle error");
491+
let restored = delta.apply(&original).unwrap();
492492
assert_eq!(restored, new_content.as_bytes());
493493
}
494494

@@ -498,7 +498,7 @@ mod tests {
498498
let new = b"Modified content here\nWith multiple lines\nAnd some different text\n".repeat(50);
499499

500500
let delta = Delta::compute(&original, &new);
501-
let restored = delta.apply(&original).expect("TODO: handle error");
501+
let restored = delta.apply(&original).unwrap();
502502

503503
assert_eq!(restored, new.to_vec());
504504
}

crates/januskey-cli/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ mod tests {
170170

171171
#[test]
172172
fn test_init_and_open() {
173-
let tmp = TempDir::new().expect("TODO: handle error");
174-
let jk = JanusKey::init(tmp.path()).expect("TODO: handle error");
173+
let tmp = TempDir::new().unwrap();
174+
let jk = JanusKey::init(tmp.path()).unwrap();
175175
assert!(JanusKey::is_initialized(tmp.path()));
176176

177-
let jk2 = JanusKey::open(tmp.path()).expect("TODO: handle error");
177+
let jk2 = JanusKey::open(tmp.path()).unwrap();
178178
assert_eq!(jk.root, jk2.root);
179179
}
180180
}

crates/januskey-cli/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ fn main() -> Result<()> {
156156
let cli = Cli::parse();
157157

158158
// Determine working directory
159-
let working_dir = cli.dir.unwrap_or_else(|| std::env::current_dir().expect("TODO: handle error"));
159+
let working_dir = match cli.dir {
160+
Some(dir) => dir,
161+
None => std::env::current_dir().context("Failed to get current directory")?,
162+
};
160163

161164
match cli.command {
162165
Commands::Init => cmd_init(&working_dir),
@@ -286,7 +289,7 @@ fn cmd_delete(
286289
pb.set_style(
287290
ProgressStyle::default_bar()
288291
.template("{spinner:.green} [{bar:40.cyan/blue}] {pos}/{len} {msg}")
289-
.expect("TODO: handle error")
292+
.expect("invariant: progress bar template is valid at compile-time")
290293
.progress_chars("#>-"),
291294
);
292295
Some(pb)

crates/januskey-cli/src/operations.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,11 @@ mod tests {
481481
use tempfile::TempDir;
482482

483483
fn setup() -> (TempDir, ContentStore, MetadataStore) {
484-
let tmp = TempDir::new().expect("TODO: handle error");
484+
let tmp = TempDir::new().unwrap();
485485
let content_store =
486-
ContentStore::new(tmp.path().join("content"), false).expect("TODO: handle error");
486+
ContentStore::new(tmp.path().join("content"), false).unwrap();
487487
let metadata_store =
488-
MetadataStore::new(tmp.path().join("metadata.json")).expect("TODO: handle error");
488+
MetadataStore::new(tmp.path().join("metadata.json")).unwrap();
489489
(tmp, content_store, metadata_store)
490490
}
491491

@@ -495,24 +495,24 @@ mod tests {
495495

496496
// Create a test file
497497
let test_file = tmp.path().join("test.txt");
498-
fs::write(&test_file, "hello world").expect("TODO: handle error");
498+
fs::write(&test_file, "hello world").unwrap();
499499

500500
// Delete it
501501
let mut executor = OperationExecutor::new(&content_store, &mut metadata_store);
502502
let delete_meta = executor
503503
.execute(FileOperation::Delete {
504504
path: test_file.clone(),
505505
})
506-
.expect("TODO: handle error");
506+
.unwrap();
507507

508508
assert!(!test_file.exists());
509509

510510
// Undo the delete
511511
let mut executor = OperationExecutor::new(&content_store, &mut metadata_store);
512-
executor.undo(&delete_meta.id).expect("TODO: handle error");
512+
executor.undo(&delete_meta.id).unwrap();
513513

514514
assert!(test_file.exists());
515-
assert_eq!(fs::read_to_string(&test_file).expect("TODO: handle error"), "hello world");
515+
assert_eq!(fs::read_to_string(&test_file).unwrap(), "hello world");
516516
}
517517

518518
#[test]
@@ -521,7 +521,7 @@ mod tests {
521521

522522
// Create a test file
523523
let test_file = tmp.path().join("test.txt");
524-
fs::write(&test_file, "original content").expect("TODO: handle error");
524+
fs::write(&test_file, "original content").unwrap();
525525

526526
// Modify it
527527
let mut executor = OperationExecutor::new(&content_store, &mut metadata_store);
@@ -530,15 +530,15 @@ mod tests {
530530
path: test_file.clone(),
531531
new_content: b"modified content".to_vec(),
532532
})
533-
.expect("TODO: handle error");
533+
.unwrap();
534534

535-
assert_eq!(fs::read_to_string(&test_file).expect("TODO: handle error"), "modified content");
535+
assert_eq!(fs::read_to_string(&test_file).unwrap(), "modified content");
536536

537537
// Undo the modify
538538
let mut executor = OperationExecutor::new(&content_store, &mut metadata_store);
539-
executor.undo(&modify_meta.id).expect("TODO: handle error");
539+
executor.undo(&modify_meta.id).unwrap();
540540

541-
assert_eq!(fs::read_to_string(&test_file).expect("TODO: handle error"), "original content");
541+
assert_eq!(fs::read_to_string(&test_file).unwrap(), "original content");
542542
}
543543

544544
#[test]
@@ -548,7 +548,7 @@ mod tests {
548548
// Create a test file
549549
let source = tmp.path().join("source.txt");
550550
let dest = tmp.path().join("dest.txt");
551-
fs::write(&source, "content").expect("TODO: handle error");
551+
fs::write(&source, "content").unwrap();
552552

553553
// Move it
554554
let mut executor = OperationExecutor::new(&content_store, &mut metadata_store);
@@ -557,14 +557,14 @@ mod tests {
557557
source: source.clone(),
558558
destination: dest.clone(),
559559
})
560-
.expect("TODO: handle error");
560+
.unwrap();
561561

562562
assert!(!source.exists());
563563
assert!(dest.exists());
564564

565565
// Undo the move
566566
let mut executor = OperationExecutor::new(&content_store, &mut metadata_store);
567-
executor.undo(&move_meta.id).expect("TODO: handle error");
567+
executor.undo(&move_meta.id).unwrap();
568568

569569
assert!(source.exists());
570570
assert!(!dest.exists());
@@ -577,7 +577,7 @@ mod tests {
577577
// Create a test file
578578
let source = tmp.path().join("source.txt");
579579
let dest = tmp.path().join("dest.txt");
580-
fs::write(&source, "content").expect("TODO: handle error");
580+
fs::write(&source, "content").unwrap();
581581

582582
// Copy it
583583
let mut executor = OperationExecutor::new(&content_store, &mut metadata_store);
@@ -586,14 +586,14 @@ mod tests {
586586
source: source.clone(),
587587
destination: dest.clone(),
588588
})
589-
.expect("TODO: handle error");
589+
.unwrap();
590590

591591
assert!(source.exists());
592592
assert!(dest.exists());
593593

594594
// Undo the copy (deletes the copy)
595595
let mut executor = OperationExecutor::new(&content_store, &mut metadata_store);
596-
executor.undo(&copy_meta.id).expect("TODO: handle error");
596+
executor.undo(&copy_meta.id).unwrap();
597597

598598
assert!(source.exists());
599599
assert!(!dest.exists());

crates/reversible-core/src/content_store.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -223,38 +223,38 @@ mod tests {
223223

224224
#[test]
225225
fn test_store_and_retrieve() {
226-
let tmp = TempDir::new().expect("TODO: handle error");
227-
let store = ContentStore::new(tmp.path().to_path_buf(), false).expect("TODO: handle error");
226+
let tmp = TempDir::new().unwrap();
227+
let store = ContentStore::new(tmp.path().to_path_buf(), false).unwrap();
228228

229229
let content = b"test content";
230-
let hash = store.store(content).expect("TODO: handle error");
230+
let hash = store.store(content).unwrap();
231231

232-
let retrieved = store.retrieve(&hash).expect("TODO: handle error");
232+
let retrieved = store.retrieve(&hash).unwrap();
233233
assert_eq!(content.to_vec(), retrieved);
234234
}
235235

236236
#[test]
237237
fn test_store_compressed() {
238-
let tmp = TempDir::new().expect("TODO: handle error");
239-
let store = ContentStore::new(tmp.path().to_path_buf(), true).expect("TODO: handle error");
238+
let tmp = TempDir::new().unwrap();
239+
let store = ContentStore::new(tmp.path().to_path_buf(), true).unwrap();
240240

241241
let content = b"test content that should compress well when repeated ".repeat(100);
242-
let hash = store.store(&content).expect("TODO: handle error");
242+
let hash = store.store(&content).unwrap();
243243

244-
let retrieved = store.retrieve(&hash).expect("TODO: handle error");
244+
let retrieved = store.retrieve(&hash).unwrap();
245245
assert_eq!(content, retrieved.as_slice());
246246
}
247247

248248
#[test]
249249
fn test_deduplication() {
250-
let tmp = TempDir::new().expect("TODO: handle error");
251-
let store = ContentStore::new(tmp.path().to_path_buf(), false).expect("TODO: handle error");
250+
let tmp = TempDir::new().unwrap();
251+
let store = ContentStore::new(tmp.path().to_path_buf(), false).unwrap();
252252

253253
let content = b"duplicate content";
254-
let hash1 = store.store(content).expect("TODO: handle error");
255-
let hash2 = store.store(content).expect("TODO: handle error");
254+
let hash1 = store.store(content).unwrap();
255+
let hash2 = store.store(content).unwrap();
256256

257257
assert_eq!(hash1, hash2);
258-
assert_eq!(store.count().expect("TODO: handle error"), 1);
258+
assert_eq!(store.count().unwrap(), 1);
259259
}
260260
}

crates/reversible-core/src/manifest.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,17 @@ mod tests {
121121

122122
#[test]
123123
fn test_generate_manifest() {
124-
let tmp = TempDir::new().expect("TODO: handle error");
124+
let tmp = TempDir::new().unwrap();
125125
let mut store =
126-
MetadataStore::new(tmp.path().join("metadata.json")).expect("TODO: handle error");
126+
MetadataStore::new(tmp.path().join("metadata.json")).unwrap();
127127

128128
let op = OperationMetadata::new(
129129
OperationType::Delete,
130130
PathBuf::from("/test/file.txt"),
131131
)
132132
.with_content_hash(ContentHash::from_bytes(b"file content"));
133133

134-
store.append(op).expect("TODO: handle error");
134+
store.append(op).unwrap();
135135

136136
let manifest = ManifestEmitter::generate("januskey", &store);
137137

@@ -145,9 +145,9 @@ mod tests {
145145

146146
#[test]
147147
fn test_empty_manifest() {
148-
let tmp = TempDir::new().expect("TODO: handle error");
148+
let tmp = TempDir::new().unwrap();
149149
let store =
150-
MetadataStore::new(tmp.path().join("metadata.json")).expect("TODO: handle error");
150+
MetadataStore::new(tmp.path().join("metadata.json")).unwrap();
151151

152152
let manifest = ManifestEmitter::generate("test", &store);
153153
assert!(manifest.contains("@manifest"));
@@ -156,15 +156,15 @@ mod tests {
156156

157157
#[test]
158158
fn test_merkle_root_deterministic() {
159-
let tmp = TempDir::new().expect("TODO: handle error");
159+
let tmp = TempDir::new().unwrap();
160160
let mut store =
161-
MetadataStore::new(tmp.path().join("metadata.json")).expect("TODO: handle error");
161+
MetadataStore::new(tmp.path().join("metadata.json")).unwrap();
162162

163163
let op = OperationMetadata::new(
164164
OperationType::Create,
165165
PathBuf::from("/a.txt"),
166166
);
167-
store.append(op).expect("TODO: handle error");
167+
store.append(op).unwrap();
168168

169169
let m1 = ManifestEmitter::generate("test", &store);
170170
let m2 = ManifestEmitter::generate("test", &store);

crates/reversible-core/src/metadata.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,21 +394,21 @@ mod tests {
394394

395395
#[test]
396396
fn test_metadata_store() {
397-
let tmp = TempDir::new().expect("TODO: handle error");
397+
let tmp = TempDir::new().unwrap();
398398
let path = tmp.path().join("metadata.json");
399399

400-
let mut store = MetadataStore::new(path.clone()).expect("TODO: handle error");
400+
let mut store = MetadataStore::new(path.clone()).unwrap();
401401

402402
let meta =
403403
OperationMetadata::new(OperationType::Delete, PathBuf::from("/test.txt"));
404404
let id = meta.id.clone();
405-
store.append(meta).expect("TODO: handle error");
405+
store.append(meta).unwrap();
406406

407407
assert_eq!(store.count(), 1);
408408
assert!(store.get(&id).is_some());
409409

410410
// Reopen and verify persistence
411-
let store2 = MetadataStore::new(path).expect("TODO: handle error");
411+
let store2 = MetadataStore::new(path).unwrap();
412412
assert_eq!(store2.count(), 1);
413413
assert!(store2.get(&id).is_some());
414414
}

0 commit comments

Comments
 (0)