Skip to content

Commit eca3220

Browse files
committed
Refactor error handling in JSON serialization and file persistence methods
1 parent 966789c commit eca3220

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,13 @@ impl JsonMutexDB {
321321
let mut buffered_writer = BufWriter::new(writer);
322322
if pretty {
323323
serde_json::to_writer_pretty(&mut buffered_writer, data_to_save)
324-
.map_err(|e| DbError::Io(IoError::new(ErrorKind::Other, e.to_string())))?;
324+
.map_err(|e| DbError::Io(IoError::other(e.to_string())))?;
325325
} else if fast_serialization {
326326
simd_json::to_writer(&mut buffered_writer, data_to_save)
327-
.map_err(|e| DbError::Io(IoError::new(ErrorKind::Other, format!("{e:?}"))))?;
327+
.map_err(|e| DbError::Io(IoError::other(format!("{e:?}"))))?;
328328
} else {
329329
serde_json::to_writer(&mut buffered_writer, data_to_save)
330-
.map_err(|e| DbError::Io(IoError::new(ErrorKind::Other, e.to_string())))?;
330+
.map_err(|e| DbError::Io(IoError::other(e.to_string())))?;
331331
}
332332
buffered_writer.flush()?; // Ensure buffer is flushed
333333
Ok(())
@@ -352,10 +352,10 @@ impl JsonMutexDB {
352352

353353
// Persist atomically (consumes temp_file)
354354
temp_file.persist(&final_path).map_err(|e| {
355-
DbError::Io(IoError::new(
356-
ErrorKind::Other,
357-
format!("Failed to atomically rename temp file: {}", e.error),
358-
))
355+
DbError::Io(IoError::other(format!(
356+
"Failed to atomically rename temp file: {}",
357+
e.error
358+
)))
359359
})?;
360360
} else {
361361
// Non-atomic: Create/truncate target file directly

0 commit comments

Comments
 (0)