diff rust/hg-core/src/dirstate/parsers.rs @ 52048:db5c202eff36

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.
author Rapha?l Gom?s <rgomes@octobus.net>
date Thu, 03 Oct 2024 00:31:25 +0200
parents 475c170bb815
children b422acba55f1
line wrap: on
line diff
--- 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)
 }