wavetermdev/waveterm · error

error getting file: %w

Error message

error getting file: %w

What it means

loadFileForRead fetches the file's metadata record (WaveFile) from the DB via dbGetZoneFile. Any DB error is wrapped as 'error getting file: %w'; a successful query with no record yields fs.ErrNotExist instead, meaning the file was never created or was deleted.

Source

Thrown at pkg/filestore/blockstore_cache.go:120

	if entry.File != nil {
		return nil
	}
	file, err := entry.loadFileForRead(ctx)
	if err != nil {
		return err
	}
	entry.File = file
	return nil
}

// does not populate the cache entry, returns err if file does not exist
func (entry *CacheEntry) loadFileForRead(ctx context.Context) (*WaveFile, error) {
	if entry.File != nil {
		return entry.File, nil
	}
	file, err := dbGetZoneFile(ctx, entry.ZoneId, entry.Name)
	if err != nil {
		return nil, fmt.Errorf("error getting file: %w", err)
	}
	if file == nil {
		return nil, fs.ErrNotExist
	}
	return file, nil
}

func withLock(s *FileStore, zoneId string, name string, fn func(*CacheEntry) error) error {
	entry := s.getEntryAndPin(zoneId, name)
	defer s.unpinEntryAndTryDelete(zoneId, name)
	entry.Lock.Lock()
	defer entry.Lock.Unlock()
	return fn(entry)
}

func withLockRtn[T any](s *FileStore, zoneId string, name string, fn func(*CacheEntry) (T, error)) (T, error) {
	var rtnVal T
	rtnErr := withLock(s, zoneId, name, func(entry *CacheEntry) error {

View on GitHub (pinned to a4447c1563)

Solutions

  1. Check errors.Is(err, fs.ErrNotExist) to distinguish 'file missing' from a real DB failure and create the file if needed.
  2. Verify DB connectivity and schema (migrations) for the filestore tables.
  3. Inspect the wrapped cause with %w/errors.Unwrap to find the driver-level error.

Example fix

// before
_, data, err := fs.ReadAt(ctx, zone, name, 0, 1024)
if err != nil { return err }
// after
_, data, err := fs.ReadAt(ctx, zone, name, 0, 1024)
if errors.Is(err, fs.ErrNotExist) { return createFileThenRetry(ctx, zone, name) }
if err != nil { return fmt.Errorf("read failed: %w", err) }
Defensive patterns

Strategy: try-catch

Try / catch

_, data, err := fs.ReadAt(ctx, zone, name, 0, n)
if errors.Is(err, fs.ErrNotExist) {
    // file missing: create it or return not-found to caller
} else if err != nil && strings.Contains(err.Error(), "error getting file") {
    // DB failure: check connectivity/migrations, inspect errors.Unwrap(err)
}

Prevention

When it happens

Trigger: loadFileIntoCache or readAt on a zone:name whose metadata row cannot be read — DB connection failure, missing/corrupt table, or the wrapped inner error from dbGetZoneFile.

Common situations: Database not migrated/initialized; DB unreachable (network, wrong DSN); racing a DeleteFile so metadata disappears mid-operation; typo in zoneId/name surfacing as DB lookup anomalies.

Related errors


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