wavetermdev/waveterm · error

failed to check if new local app exists: %w

Error message

failed to check if new local app exists: %w

What it means

If the existence check for the prospective local destination directory fails with an error other than NotExist, RenameLocalApp aborts with "failed to check if new local app exists: %w". This avoids wrongly concluding the name is free when the stat itself failed.

Source

Thrown at pkg/waveappstore/waveappstore.go:690

	} else if !os.IsNotExist(err) {
		return fmt.Errorf("failed to check local app: %w", err)
	}

	if _, err := os.Stat(oldDraftDir); err == nil {
		draftExists = true
	} else if !os.IsNotExist(err) {
		return fmt.Errorf("failed to check draft app: %w", err)
	}

	if !localExists && !draftExists {
		return fmt.Errorf("app '%s' does not exist in local or draft namespace", appName)
	}

	// Check if new app name already exists in either namespace
	if _, err := os.Stat(newLocalDir); err == nil {
		return fmt.Errorf("local app '%s' already exists", newAppName)
	} else if !os.IsNotExist(err) {
		return fmt.Errorf("failed to check if new local app exists: %w", err)
	}

	if _, err := os.Stat(newDraftDir); err == nil {
		return fmt.Errorf("draft app '%s' already exists", newAppName)
	} else if !os.IsNotExist(err) {
		return fmt.Errorf("failed to check if new draft app exists: %w", err)
	}

	// Rename local app if it exists
	if localExists {
		if err := os.Rename(oldLocalDir, newLocalDir); err != nil {
			return fmt.Errorf("failed to rename local app: %w", err)
		}
	}

	// Rename draft app if it exists
	if draftExists {
		if err := os.Rename(oldDraftDir, newDraftDir); err != nil {

View on GitHub (pinned to a4447c1563)

Solutions

  1. Fix permissions on ~/waveapps/local so the process can stat entries there
  2. Verify the volume is mounted and healthy
  3. Run under the account that owns the waveapps directory
Defensive patterns

Strategy: try-catch

Validate before calling

localDir := filepath.Join(wavebase.GetHomeDir(), "waveapps", "local")
if err := os.Access(localDir, os.R_OK); err != nil {
    return fmt.Errorf("cannot read local dir: %w", err)
}

Try / catch

if err := waveappstore.RenameLocalApp(oldName, newName); err != nil {
    var pe *fs.PathError
    if strings.Contains(err.Error(), "failed to check if new local app exists") && errors.As(err, &pe) {
        return fmt.Errorf("stat failed on %s: %w", pe.Path, pe.Err)
    }
    return err
}

Prevention

When it happens

Trigger: os.Stat(newLocalDir) returns a non-ENOENT error: permission denied on ~/waveapps/local, I/O error, or an unreadable parent directory.

Common situations: Permission-restricted waveapps tree, destination directory owned by another user, failing disk or unmounted volume during the rename.

Related errors


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