Skip to content

Commit a709047

Browse files
committed
fix(tags): improve error message specificity in parse_for_each_ref_line
- Include expected and actual parts count in error message for better debugging - Add test coverage for invalid format error handling - Change from generic "Invalid format" to specific "expected 9 parts, got X"
1 parent 1a8f946 commit a709047

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/commands/tag.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,10 @@ fn parse_for_each_ref_line(line: &str) -> Result<Tag> {
394394
let parts: Vec<&str> = line.split('|').collect();
395395

396396
if parts.len() < 9 {
397-
return Err(GitError::CommandFailed(
398-
"Invalid for-each-ref format".to_string(),
399-
));
397+
return Err(GitError::CommandFailed(format!(
398+
"Invalid for-each-ref format: expected 9 parts, got {}",
399+
parts.len()
400+
)));
400401
}
401402

402403
let name = parts[0].to_string();
@@ -753,4 +754,21 @@ mod tests {
753754
// Clean up
754755
fs::remove_dir_all(&test_path).unwrap();
755756
}
757+
758+
#[test]
759+
fn test_parse_for_each_ref_line_invalid_format() {
760+
// Test with insufficient parts (should have 9 parts minimum)
761+
let invalid_line = "tag1|commit|abc123"; // Only 3 parts instead of 9
762+
let result = parse_for_each_ref_line(invalid_line);
763+
764+
assert!(result.is_err());
765+
766+
if let Err(GitError::CommandFailed(msg)) = result {
767+
assert!(msg.contains("Invalid for-each-ref format"));
768+
assert!(msg.contains("expected 9 parts"));
769+
assert!(msg.contains("got 3"));
770+
} else {
771+
panic!("Expected CommandFailed error with specific message");
772+
}
773+
}
756774
}

0 commit comments

Comments
 (0)