From: Nicolas Patry Date: Mon, 13 Mar 2023 10:35:40 +0000 (+0100) Subject: Nicer error when failed to find tensor in Rust. (#191) X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=454924be76cb1c3c8c270dd775fc4c8280ae3ebd;p=safetensors.git Nicer error when failed to find tensor in Rust. (#191) Co-authored-by: Ubuntu --- diff --git a/safetensors/src/tensor.rs b/safetensors/src/tensor.rs index 9c6cfce..c4a798d 100644 --- a/safetensors/src/tensor.rs +++ b/safetensors/src/tensor.rs @@ -24,7 +24,7 @@ pub enum SafeTensorError { /// The header length is invalid InvalidHeaderLength, /// The tensor name was not found in the archive - TensorNotFound, + TensorNotFound(String), /// Invalid information between shape, dtype and the proposed offsets in the file TensorInvalidInfo, /// The offsets declared for tensor with name `String` in the header are invalid @@ -348,10 +348,10 @@ impl<'data> SafeTensors<'data> { data: &self.data[info.data_offsets.0..info.data_offsets.1], }) } else { - Err(SafeTensorError::TensorNotFound) + Err(SafeTensorError::TensorNotFound(tensor_name.to_string())) } } else { - Err(SafeTensorError::TensorNotFound) + Err(SafeTensorError::TensorNotFound(tensor_name.to_string())) } }