rust-parsers: use the same error message as with the higher-level code
authorRaphaël Gomès <rgomes@octobus.net>
Thu, 03 Oct 2024 00:31:25 +0200
changeset 52052 db5c202eff36
parent 52051 503b7688f057
child 52053 af54626bf358
rust-parsers: use the same error message as with the higher-level code This can happen at two places, but it's not really enough time to justify it being refactored. Let's ensure we have the same error message, the newer one being slightly more helpful.
rust/hg-core/src/dirstate/parsers.rs
--- a/rust/hg-core/src/dirstate/parsers.rs	Thu Oct 03 01:52:44 2024 +0200
+++ b/rust/hg-core/src/dirstate/parsers.rs	Thu Oct 03 00:31:25 2024 +0200
@@ -23,8 +23,13 @@
 pub fn parse_dirstate_parents(
     contents: &[u8],
 ) -> Result<&DirstateParents, HgError> {
-    let (parents, _rest) = DirstateParents::from_bytes(contents)
-        .map_err(|_| HgError::corrupted("Too little data for dirstate."))?;
+    let contents_len = contents.len();
+    let (parents, _rest) =
+        DirstateParents::from_bytes(contents).map_err(|_| {
+            HgError::corrupted(format!(
+                "Too little data for dirstate: {contents_len} bytes.",
+            ))
+        })?;
     Ok(parents)
 }