wavetermdev/waveterm · error

invalid pid: %d

Error message

invalid pid: %d

What it means

Returned when the pid in an RPC request is invalid (zero or negative), identified by the %d value in the message.

Source

Thrown at pkg/wshrpc/wshremote/wshremote.go:143

	}
	impl.Log("created symlink %s -> %s\n", symlinkPath, impl.SockName)
	return nil
}

func (impl *ServerImpl) getWshPath() (string, error) {
	if impl.IsLocal {
		return filepath.Join(wavebase.GetWaveDataDir(), "bin", "wsh"), nil
	}
	wshPath, err := wavebase.ExpandHomeDir("~/.waveterm/bin/wsh")
	if err != nil {
		return "", fmt.Errorf("cannot expand wsh path: %w", err)
	}
	return wshPath, nil
}

func (impl *ServerImpl) BadgeWatchPidCommand(ctx context.Context, data wshrpc.CommandBadgeWatchPidData) error {
	if data.Pid <= 0 {
		return fmt.Errorf("invalid pid: %d", data.Pid)
	}
	if data.ORef.IsEmpty() {
		return fmt.Errorf("oref is required")
	}
	if data.BadgeId == "" {
		return fmt.Errorf("badgeid is required")
	}
	go func() {
		defer func() {
			panichandler.PanicHandler("BadgeWatchPidCommand", recover())
		}()
		for {
			time.Sleep(time.Second)
			if unixutil.IsPidRunning(data.Pid) {
				continue
			}
			orefStr := data.ORef.String()
			event := wps.WaveEvent{

View on GitHub (pinned to a4447c1563)

Solutions

  1. Ensure the process was successfully started and capture its real PID before watching
  2. Skip/stop the badge watch when the process has exited instead of calling with 0/-1
  3. Validate pid > 0 in the caller before issuing the RPC

Example fix

// before
wshrpc.BadgeWatchPidCommand(ctx, wshrpc.CommandBadgeWatchPidData{Pid: proc.Pid})
// after
if proc.Pid > 0 {
    wshrpc.BadgeWatchPidCommand(ctx, wshrpc.CommandBadgeWatchPidData{Pid: proc.Pid})
}
Defensive patterns

Strategy: validation

Validate before calling

if data.Pid <= 0 {
    return fmt.Errorf("refusing to watch badge: pid %d invalid", data.Pid)
}

Try / catch

if err := BadgeWatchPidCommand(ctx, data); err != nil {
    if strings.Contains(err.Error(), "invalid pid") {
        return nil // skip badge watch for dead/unspawned process
    }
    return err
}

Prevention

When it happens

Trigger: Calling BadgeWatchPidCommand with CommandBadgeWatchPidData.Pid == 0 or negative — typically an uninitialized struct or a failed process lookup upstream.

Common situations: Frontend sends badge data before the process actually spawned; a lookup returned (-1 or 0) on process-exit and the caller forwards it anyway.

Understand the failure class

Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/e25097e7e66f23dc. Report an issue: GitHub.