wavetermdev/waveterm · error

error deleting file: %v

Error message

error deleting file: %v

What it means

FileStore.DeleteFile deletes a file's metadata and parts via dbDeleteFile inside a per-file lock. If the database delete fails for any reason, the cause is wrapped as 'error deleting file: %v' and returned. The cache entry is only cleared when the delete succeeds.

Source

Thrown at pkg/filestore/blockstore.go:158

		now := time.Now().UnixMilli()
		file := &WaveFile{
			ZoneId:    zoneId,
			Name:      name,
			Size:      0,
			CreatedTs: now,
			ModTs:     now,
			Opts:      opts,
			Meta:      meta,
		}
		return dbInsertFile(ctx, file)
	})
}

func (s *FileStore) DeleteFile(ctx context.Context, zoneId string, name string) error {
	return withLock(s, zoneId, name, func(entry *CacheEntry) error {
		err := dbDeleteFile(ctx, zoneId, name)
		if err != nil {
			return fmt.Errorf("error deleting file: %v", err)
		}
		entry.clear()
		return nil
	})
}

func (s *FileStore) DeleteZone(ctx context.Context, zoneId string) error {
	fileNames, err := dbGetZoneFileNames(ctx, zoneId)
	if err != nil {
		return fmt.Errorf("error getting zone files: %v", err)
	}
	for _, name := range fileNames {
		s.DeleteFile(ctx, zoneId, name)
	}
	return nil
}

// if file doesn't exsit, returns fs.ErrNotExist

View on GitHub (pinned to a4447c1563)

Solutions

  1. Inspect the wrapped cause (%v) to see the underlying DB error; retry transient failures with a fresh, non-cancelled context.
  2. Ensure the FileStore and its backing DB are open and initialized before deleting.
  3. Check the context passed to DeleteFile for early cancellation/deadline; propagate a live context from the caller.
  4. If the error persists, verify integrity of the backing store and re-open/reinitialize it.

Example fix

// before
err := store.DeleteFile(ctx, zoneId, name)
// after
err := store.DeleteFile(ctx, zoneId, name)
if err != nil {
	if ctx.Err() != nil {
		err = store.DeleteFile(context.Background(), zoneId, name) // retry with live context
	}
}
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check: ensure store is usable and context is live
if ctx.Err() != nil { return ctx.Err() }
// optionally confirm the file exists if your flow expects it:
// _, err := store.StatFile(ctx, zoneId, name)

Try / catch

if err := store.DeleteFile(ctx, zoneId, name); err != nil {
	if strings.Contains(err.Error(), "error deleting file:") {
		// unwrap and retry transient failures
		time.Sleep(100 * time.Millisecond)
		err = store.DeleteFile(ctx, zoneId, name)
	}
	if err != nil {
		return fmt.Errorf("delete %s/%s: %w", zoneId, name, err)
	}
}

Prevention

When it happens

Trigger: dbDeleteFile returns an error: the underlying store/DB is closed or unavailable, the context is cancelled/timed out mid-delete, or a storage-layer error occurs while removing file rows/parts.

Common situations: Calling DeleteFile after the backing store was shut down; request contexts cancelled by upstream timeouts; database corruption or locked store during concurrent operations; transient storage failures in embedded DB backends.

Related errors


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