@@ -27,13 +27,13 @@ func SendChunkedFile(
2727 chunkSize := int (header .Header .GetChunkSize ())
2828 total := int (header .Header .GetFileMeta ().GetSize ())
2929 if chunkSize == 0 || chunkCount == 0 || total == 0 {
30- return fmt .Errorf ("zero in header: %+v" , header .Header )
30+ return fmt .Errorf ("file size in header is zero : %+v" , header .Header )
3131 }
3232 if err := dst .Send (& v1.FileDataChunk {
3333 Meta : meta ,
3434 Chunk : & header ,
3535 }); err != nil {
36- return fmt .Errorf ("%w: send error ( header) " , err )
36+ return fmt .Errorf ("unable to send header chunk: %w " , err )
3737 }
3838 // allocate the buffer we need for reading from io.Reader
3939 // this is set to the size of the chunks we need to send.
@@ -48,7 +48,7 @@ func SendChunkedFile(
4848 total -= n
4949 if err != nil && total != 0 {
5050 // partial read
51- return fmt .Errorf ("%w: failed read" , err )
51+ return fmt .Errorf ("unable to read chunk id %d: %w" , i , err )
5252 }
5353 if err = dst .Send (& v1.FileDataChunk {
5454 Meta : meta ,
@@ -59,7 +59,7 @@ func SendChunkedFile(
5959 },
6060 },
6161 }); err != nil {
62- return fmt .Errorf ("%w: send error (content)" , err )
62+ return fmt .Errorf ("unable to send chunk id %d: %w" , i , err )
6363 }
6464 }
6565
@@ -75,7 +75,7 @@ func RecvChunkedFile(
7575 // receive the header first
7676 chunk , err := src .Recv ()
7777 if err != nil {
78- return header , fmt .Errorf ("%w: header error " , err )
78+ return header , fmt .Errorf ("unable to receive header chunk: %w " , err )
7979 }
8080
8181 // validate and extract header info
@@ -90,7 +90,7 @@ func RecvChunkedFile(
9090 total := int (header .GetSize ())
9191
9292 if chunkSize == 0 || chunkCount == 0 || total == 0 {
93- return header , fmt .Errorf ("zero in header: %v" , headerChunk )
93+ return header , fmt .Errorf ("file size in header is zero : %+ v" , headerChunk )
9494 }
9595
9696 return header , recvContents (src , dst , chunkCount , chunkSize , total )
@@ -107,15 +107,15 @@ func recvContents(
107107 for i := 0 ; i < chunkCount ; i ++ {
108108 chunk , err := src .Recv ()
109109 if err != nil {
110- return fmt .Errorf ("%w: failed to read content" , err )
110+ return fmt .Errorf ("unable to receive chunk id %d: %w" , i , err )
111111 }
112112
113113 if err = validateRecvChunk (chunk , chunkSize , chunkCount - 1 , i ); err != nil {
114114 return err
115115 }
116116 data := chunk .GetContent ().GetData ()
117117 if _ , err = dst .Write (data ); err != nil {
118- return fmt .Errorf ("%w: failed write" , err )
118+ return fmt .Errorf ("unable to write chunk id %d: %w" , i , err )
119119 }
120120 totalSize -= len (data )
121121 if 0 > totalSize {
@@ -129,17 +129,17 @@ func recvContents(
129129 return nil
130130}
131131
132- func validateRecvChunk (chunk * v1.FileDataChunk , chunkSize , lastChunkIndex , i int ) error {
132+ func validateRecvChunk (chunk * v1.FileDataChunk , chunkSize , lastChunkIndex , chunkID int ) error {
133133 content := chunk .GetContent ()
134134 if content == nil {
135- return fmt .Errorf ("no content in chunk id %d" , i )
135+ return fmt .Errorf ("no content in chunk id %d" , chunkID )
136136 }
137- if content .GetChunkId () != uint32 (i ) {
137+ if content .GetChunkId () != uint32 (chunkID ) {
138138 return fmt .Errorf ("content chunk id of %d does not match expected id of %d" ,
139- content .GetChunkId (), i )
139+ content .GetChunkId (), chunkID )
140140 }
141141 data := content .GetData ()
142- if len (data ) != chunkSize && i != lastChunkIndex {
142+ if len (data ) != chunkSize && chunkID != lastChunkIndex {
143143 return fmt .Errorf ("content chunk size of %d does not match expected size of %d" ,
144144 len (data ), chunkSize )
145145 }
0 commit comments