wavetermdev/waveterm · error
file %q already exists
Error message
file %q already exists
What it means
Returned when the target file already exists and the operation does not overwrite existing files. The path is quoted via %q.
Source
Thrown at pkg/wshrpc/wshremote/wshremote_file.go:421
if err != nil {
rtn[path] = wshrpc.FileInfo{
Path: wavebase.ReplaceHomeDir(cleanedPath),
Dir: computeDirPart(cleanedPath),
Name: filepath.Base(cleanedPath),
StatError: err.Error(),
SupportsMkdir: true,
}
continue
}
rtn[path] = *fileInfo
}
return rtn, nil
}
func (impl *ServerImpl) RemoteFileTouchCommand(ctx context.Context, path string) error {
cleanedPath := filepath.Clean(wavebase.ExpandHomeDirSafe(path))
if _, err := os.Stat(cleanedPath); err == nil {
return fmt.Errorf("file %q already exists", path)
}
if err := os.MkdirAll(filepath.Dir(cleanedPath), 0755); err != nil {
return fmt.Errorf("cannot create directory %q: %w", filepath.Dir(cleanedPath), err)
}
if err := os.WriteFile(cleanedPath, []byte{}, 0644); err != nil {
return fmt.Errorf("cannot create file %q: %w", cleanedPath, err)
}
return nil
}
func (impl *ServerImpl) RemoteFileMoveCommand(ctx context.Context, data wshrpc.CommandFileCopyData) error {
destUri := data.DestUri
srcUri := data.SrcUri
destConn, err := connparse.ParseURIAndReplaceCurrentHost(ctx, destUri)
if err != nil {
return fmt.Errorf("cannot parse destination URI %q: %w", srcUri, err)
}View on GitHub (pinned to a4447c1563)
Solutions
- Check existence first with RemoteFileInfoCommand and skip touch if present.
- Delete the existing file if overwrite is intended (RemoteFileDeleteCommand) then touch.
- Use a different destination path or add a timestamp suffix.
Example fix
// before
wshclient.RemoteFileTouchCommand(ctx, p, nil)
// after
if _, err := wshclient.RemoteFileInfoCommand(ctx, p, nil); errors.Is(err, fs.ErrNotExist) {
wshclient.RemoteFileTouchCommand(ctx, p, nil)
} Defensive patterns
Strategy: validation
Validate before calling
if _, err := wshclient.RemoteFileInfoCommand(ctx, path, nil); err == nil {
return nil // already exists, skip touch
} Try / catch
err := wshclient.RemoteFileTouchCommand(ctx, path, nil)
if err != nil && strings.Contains(err.Error(), "already exists") {
return nil // idempotent touch
} Prevention
- Make touch calls idempotent by checking existence
- Serialize create operations across clients
- Do not assume Unix touch update-mtime semantics
When it happens
Trigger: Calling RemoteFileTouchCommand with a path that already exists as a file, directory, or symlink.
Common situations: Race where another client created the file first; re-running a script twice; assuming Unix touch semantics (which updates mtime instead of erroring).
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- destination %q already exists
- accessing file %s: %w
- getting absolute path for %s: %w
- reading directory %s: %w
- reading file %s: %w
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/c6fc25ba5d917c63.
Report an issue: GitHub.