wavetermdev/waveterm · error
cwd is empty
Error message
cwd is empty
What it means
checkCwd validates the working directory before spawning a local shell process. If the cwd string is empty, it returns "cwd is empty" without attempting any I/O. This guards cmd.Dir from being set to an invalid empty value and failing later in exec.
Source
Thrown at pkg/shellexec/shellexec.go:112
}
}
func ExitCodeFromWaitErr(err error) int {
if err == nil {
return 0
}
if exitErr, ok := err.(*exec.ExitError); ok {
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
return status.ExitStatus()
}
}
return -1
}
func checkCwd(cwd string) error {
if cwd == "" {
return fmt.Errorf("cwd is empty")
}
if _, err := os.Stat(cwd); err != nil {
return fmt.Errorf("error statting cwd %q: %w", cwd, err)
}
return nil
}
type PipePty struct {
remoteStdinWrite *os.File
remoteStdoutRead *os.File
}
func (pp *PipePty) Fd() uintptr {
return pp.remoteStdinWrite.Fd()
}
func (pp *PipePty) Name() string {
return "pipe-pty"View on GitHub (pinned to a4447c1563)
Solutions
- Set a valid cwd before starting the shell (default to os.UserHomeDir() or "/")
- Ensure the block controller's state carries a non-empty cwd
- Fix connection/workspace config so cwd resolves to the user's home
Example fix
// before
proc, err := shellexec.StartLocalShellProc(ctx, termSize, cmdStr, cmdOpts, "")
// after
cwd := state.Cwd
if cwd == "" {
home, herr := os.UserHomeDir()
if herr != nil { home = "/" }
cwd = home
}
proc, err := shellexec.StartLocalShellProc(ctx, termSize, cmdStr, cmdOpts, cwd) Defensive patterns
Strategy: validation
Validate before calling
func ensureCwd(cwd string) (string, error) {
if cwd == "" {
home, err := os.UserHomeDir()
if err != nil { return "", err }
return home, nil
}
return cwd, nil
} Try / catch
proc, err := shellexec.StartLocalShellProc(ctx, termSize, cmdStr, cmdOpts, cwd)
if err != nil && strings.Contains(err.Error(), "cwd is empty") {
cwd, _ = os.UserHomeDir()
proc, err = shellexec.StartLocalShellProc(ctx, termSize, cmdStr, cmdOpts, cwd)
} Prevention
- Always initialize block state cwd from the user's home directory
- Validate cwd at config-load time, not just at spawn time
- Never persist an empty cwd into shell state
When it happens
Trigger: Calling StartLocalShellProc with a block controller / shell state whose cwd field is unset (empty string), e.g. a block created without a valid working directory.
Common situations: Block state missing cwd because the connection config never resolved a home directory, a fresh install where home is unset, or the shell state was cleared.
Related errors
- error statting cwd %q: %w
- invalid AIMessage: %w
- part %d: text type requires non-empty text field
- invalid environment variable name: %q
- invalid format of user@host argument
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/04399f2c46b21a5f.
Report an issue: GitHub.