From 454924be76cb1c3c8c270dd775fc4c8280ae3ebd Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Mon, 13 Mar 2023 11:35:40 +0100 Subject: [PATCH] Nicer error when failed to find tensor in Rust. (#191) Co-authored-by: Ubuntu --- safetensors/src/tensor.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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())) } } -- 2.43.0