Skip to content

Commit ca76adf

Browse files
Add file existence validation for local-to-remote copies
- Validate local file exists before attempting workspace connection - Provide clear error message when file doesn't exist - Improves UX by failing fast on missing files - Only validates for upload operations (local-to-remote) Co-Authored-By: Alec Fong <alecsanf@usc.edu>
1 parent 634e943 commit ca76adf

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

pkg/cmd/copy/copy.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package copy
33
import (
44
"errors"
55
"fmt"
6+
"os"
67
"os/exec"
78
"strings"
89
"time"
@@ -67,6 +68,13 @@ func runCopyCommand(t *terminal.Terminal, cstore CopyStore, source, dest string,
6768
return breverrors.WrapAndTrace(err)
6869
}
6970

71+
if isUpload {
72+
err = validateLocalFile(localPath)
73+
if err != nil {
74+
return breverrors.WrapAndTrace(err)
75+
}
76+
}
77+
7078
workspace, err := prepareWorkspace(t, cstore, workspaceNameOrID)
7179
if err != nil {
7280
return breverrors.WrapAndTrace(err)
@@ -162,6 +170,17 @@ func setupSSHConnection(t *terminal.Terminal, cstore CopyStore, workspace *entit
162170
return sshName, nil
163171
}
164172

173+
func validateLocalFile(localPath string) error {
174+
_, err := os.Stat(localPath)
175+
if err != nil {
176+
if os.IsNotExist(err) {
177+
return breverrors.NewValidationError(fmt.Sprintf("local file does not exist: %s", localPath))
178+
}
179+
return breverrors.WrapAndTrace(fmt.Errorf("cannot access local file %s: %w", localPath, err))
180+
}
181+
return nil
182+
}
183+
165184
func parseWorkspacePath(path string) (workspace, filePath string, err error) {
166185
if !strings.Contains(path, ":") {
167186
return "", path, nil

0 commit comments

Comments
 (0)