{"record":{"id":"e4884b4549df112c","repo":"wavetermdev/waveterm","slug":"error-deleting-file-v","errorCode":null,"errorMessage":"error deleting file: %v","messagePattern":"error deleting file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/filestore/blockstore.go","lineNumber":158,"sourceCode":"\t\tnow := time.Now().UnixMilli()\n\t\tfile := &WaveFile{\n\t\t\tZoneId:    zoneId,\n\t\t\tName:      name,\n\t\t\tSize:      0,\n\t\t\tCreatedTs: now,\n\t\t\tModTs:     now,\n\t\t\tOpts:      opts,\n\t\t\tMeta:      meta,\n\t\t}\n\t\treturn dbInsertFile(ctx, file)\n\t})\n}\n\nfunc (s *FileStore) DeleteFile(ctx context.Context, zoneId string, name string) error {\n\treturn withLock(s, zoneId, name, func(entry *CacheEntry) error {\n\t\terr := dbDeleteFile(ctx, zoneId, name)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error deleting file: %v\", err)\n\t\t}\n\t\tentry.clear()\n\t\treturn nil\n\t})\n}\n\nfunc (s *FileStore) DeleteZone(ctx context.Context, zoneId string) error {\n\tfileNames, err := dbGetZoneFileNames(ctx, zoneId)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error getting zone files: %v\", err)\n\t}\n\tfor _, name := range fileNames {\n\t\ts.DeleteFile(ctx, zoneId, name)\n\t}\n\treturn nil\n}\n\n// if file doesn't exsit, returns fs.ErrNotExist","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/filestore/blockstore.go#L140-L176","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the wrapped cause (%v) to see the underlying DB error; retry transient failures with a fresh, non-cancelled context.","Ensure the FileStore and its backing DB are open and initialized before deleting.","Check the context passed to DeleteFile for early cancellation/deadline; propagate a live context from the caller.","If the error persists, verify integrity of the backing store and re-open/reinitialize it."],"exampleFix":"// before\nerr := store.DeleteFile(ctx, zoneId, name)\n// after\nerr := store.DeleteFile(ctx, zoneId, name)\nif err != nil {\n\tif ctx.Err() != nil {\n\t\terr = store.DeleteFile(context.Background(), zoneId, name) // retry with live context\n\t}\n}","handlingStrategy":"try-catch","validationCode":"// pre-check: ensure store is usable and context is live\nif ctx.Err() != nil { return ctx.Err() }\n// optionally confirm the file exists if your flow expects it:\n// _, err := store.StatFile(ctx, zoneId, name)","typeGuard":null,"tryCatchPattern":"if err := store.DeleteFile(ctx, zoneId, name); err != nil {\n\tif strings.Contains(err.Error(), \"error deleting file:\") {\n\t\t// unwrap and retry transient failures\n\t\ttime.Sleep(100 * time.Millisecond)\n\t\terr = store.DeleteFile(ctx, zoneId, name)\n\t}\n\tif err != nil {\n\t\treturn fmt.Errorf(\"delete %s/%s: %w\", zoneId, name, err)\n\t}\n}","preventionTips":["Keep the FileStore/DB open for the lifetime of delete operations.","Always pass a live context; avoid reusing cancelled/timed-out contexts.","Retry transient DB errors with backoff.","Treat absence errors distinctly from storage failures when applicable."],"tags":["database","filestore","delete"],"backgroundTag":"storage-operation-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}