Skip to content

Commit

Permalink
fix: return more descriptive error message on some cases of cli uploa…
Browse files Browse the repository at this point in the history
…d fail
  • Loading branch information
lleyton committed Dec 15, 2024
1 parent 17c0ecc commit b2dc218
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion subatomic-cli/cmd/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ var uploadCmd = &cobra.Command{
"Upload "+file.Name(),
)

if _, err := io.Copy(io.MultiWriter(formWriter, bar), file); err != nil {
// io.Copy will return ErrClosedPipe when the server closes the connection or if the network connection is lost during file upload
// Ignoring this error allows us to handle the error thrown from the request.Do() call
// This will give us a more informative error in the case where the server closes the connection, because we can check the response status code
// In the case of a network connection loss, request.Do() should still return an error, which we can handle
if _, err := io.Copy(io.MultiWriter(formWriter, bar), file); err != nil && !errors.Is(err, io.ErrClosedPipe) {
return err
}
}
Expand Down

0 comments on commit b2dc218

Please sign in to comment.