]> khamidou — GitHub mirrors - safetensors.git/commitdiff
Nicer error when failed to find tensor in Rust. (#191)
authorNicolas Patry <patry.nicolas@protonmail.com>
Mon, 13 Mar 2023 10:35:40 +0000 (11:35 +0100)
committerGitHub <noreply@github.com>
Mon, 13 Mar 2023 10:35:40 +0000 (11:35 +0100)
Co-authored-by: Ubuntu <ubuntu@ip-172-31-34-94.eu-west-3.compute.internal>
safetensors/src/tensor.rs

index 9c6cfce222a2bf732f81fb8765e8d80b748c5b42..c4a798d086e8ef48986937b6f3ad8fc8ef5d00bb 100644 (file)
@@ -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()))
         }
     }