@@ -26,9 +26,6 @@ impl crate::ForgeFS {
2626 let path_ref = path. as_ref ( ) ;
2727
2828 // Basic validation
29- if start_line == 0 || end_line == 0 {
30- return Err ( Error :: StartBeyondFileSize { start : start_line, total : 0 } . into ( ) ) ;
31- }
3229 if start_line > end_line {
3330 return Err ( Error :: StartGreaterThanEnd { start : start_line, end : end_line } . into ( ) ) ;
3431 }
@@ -38,6 +35,10 @@ impl crate::ForgeFS {
3835 . await
3936 . with_context ( || format ! ( "Failed to open file {}" , path_ref. display( ) ) ) ?;
4037
38+ if start_line == 0 || end_line == 0 {
39+ return Err ( Error :: IndexStartingWithZero { start : start_line, end : end_line } . into ( ) ) ;
40+ }
41+
4142 let ( is_text, file_type) = Self :: is_binary ( & mut file) . await ?;
4243 if !is_text {
4344 return Err ( Error :: BinaryFileNotSupported ( file_type) . into ( ) ) ;
@@ -47,7 +48,10 @@ impl crate::ForgeFS {
4748 let content = tokio:: fs:: read_to_string ( path_ref)
4849 . await
4950 . with_context ( || format ! ( "Failed to read file content from {}" , path_ref. display( ) ) ) ?;
50-
51+ if start_line < 2 && content. is_empty ( ) {
52+ // If the file is empty, return empty content
53+ return Ok ( ( String :: new ( ) , FileInfo :: new ( start_line, end_line, 0 ) ) ) ;
54+ }
5155 // Split into lines
5256 let lines: Vec < & str > = content. lines ( ) . collect ( ) ;
5357 let total_lines = lines. len ( ) as u64 ;
0 commit comments