Skip to content

Commit c021480

Browse files
committed
Add some error context
1 parent 99b04c5 commit c021480

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

splashsurf/src/io.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::io::Read;
33
use std::io::{BufReader, BufWriter, Write};
44
use std::path::Path;
55

6-
use anyhow::anyhow;
6+
use anyhow::{anyhow, Context};
77
use na::Vector3;
88
use vtkio::model::{DataSet, Version, Vtk};
99
use vtkio::{export_be, import_be};
@@ -38,7 +38,7 @@ pub fn particles_from_coords<RealOut: Real, RealIn: Real>(
3838
coords: &Vec<RealIn>,
3939
) -> Result<Vec<Vector3<RealOut>>, anyhow::Error> {
4040
if coords.len() % 3 != 0 {
41-
anyhow!("The number of values in the particle data point buffer is not divisable by 3");
41+
anyhow!("The number of values in the particle data point buffer is not divisible by 3");
4242
}
4343

4444
let num_points = coords.len() / 3;
@@ -79,9 +79,7 @@ pub fn particles_from_dataset<R: Real>(
7979
pub fn particles_from_xyz<R: Real, P: AsRef<Path>>(
8080
xyz_file: P,
8181
) -> Result<Vec<Vector3<R>>, anyhow::Error> {
82-
let xyz_file = xyz_file.as_ref();
83-
84-
let file = File::open(xyz_file)?;
82+
let file = File::open(xyz_file).context("Unable to open xyz file for reading")?;
8583
let mut reader = BufReader::new(file);
8684

8785
let mut buffer = [0u8; 3 * 4];
@@ -114,7 +112,7 @@ pub fn particles_from_xyz<R: Real, P: AsRef<Path>>(
114112
#[allow(dead_code)]
115113
pub fn to_binary_f32<R: Real, P: AsRef<Path>>(file: P, values: &[R]) -> Result<(), anyhow::Error> {
116114
let file = file.as_ref();
117-
let file = File::create(file)?;
115+
let file = File::create(file).context("Unable to create binary file")?;
118116
let mut writer = BufWriter::new(file);
119117

120118
for v in values {

0 commit comments

Comments
 (0)