{"record":{"id":"dc9cc65e8ec39e78","repo":"wavetermdev/waveterm","slug":"error-getting-zone-files-v","errorCode":null,"errorMessage":"error getting zone files: %v","messagePattern":"error getting zone files: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/filestore/blockstore.go","lineNumber":168,"sourceCode":"\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\nfunc (s *FileStore) Stat(ctx context.Context, zoneId string, name string) (*WaveFile, error) {\n\treturn withLockRtn(s, zoneId, name, func(entry *CacheEntry) (*WaveFile, error) {\n\t\tfile, err := entry.loadFileForRead(ctx)\n\t\tif err != nil {\n\t\t\tif err == fs.ErrNotExist {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\treturn nil, fmt.Errorf(\"error getting file: %v\", err)\n\t\t}\n\t\treturn file.DeepCopy(), nil","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/filestore/blockstore.go#L150-L186","documentation":"DeleteZone first enumerates all file names in a zone via dbGetZoneFileNames, then deletes each file. If the enumeration query fails, the cause is wrapped as 'error getting zone files: %v'. Note that per-file DeleteFile errors during the loop are silently ignored, so this error only covers the listing step.","triggerScenarios":"dbGetZoneFileNames returns an error: backing DB unavailable/closed, context cancelled or deadline exceeded, or a storage-layer failure while querying file names for the zone.","commonSituations":"Tearing down zones after the store has been closed; cancelled request contexts during shutdown; DB lock contention with concurrent writers; corrupted zone metadata preventing the name listing.","solutions":["Inspect the wrapped cause to identify the DB failure; retry transient errors with a valid context.","Ensure the store/DB is open and reachable before calling DeleteZone.","Check for context cancellation from the caller and use a fresh context for teardown-time deletes.","Verify the zone metadata tables are intact if the error is persistent."],"exampleFix":"// before\nfor _, name := range fileNames {\n\ts.DeleteFile(ctx, zoneId, name) // errors swallowed\n}\n// after\nfor _, name := range fileNames {\n\tif err := s.DeleteFile(ctx, zoneId, name); err != nil {\n\t\treturn fmt.Errorf(\"error deleting file %q in zone: %w\", name, err)\n\t}\n}","handlingStrategy":"try-catch","validationCode":"// pre-check context and store availability before teardown\nif ctx.Err() != nil { return ctx.Err() }","typeGuard":null,"tryCatchPattern":"if err := store.DeleteZone(ctx, zoneId); err != nil {\n\tif strings.Contains(err.Error(), \"error getting zone files:\") {\n\t\t// retry transient listing failure\n\t\terr = store.DeleteZone(ctx, zoneId)\n\t}\n\tif err != nil {\n\t\treturn fmt.Errorf(\"delete zone %s: %w\", zoneId, err)\n\t}\n}","preventionTips":["Use a fresh context (not a request-scoped one) for shutdown-time zone deletion.","Ensure the store is open before teardown deletes.","Handle per-file delete failures explicitly; DeleteZone ignores them today.","Log and monitor wrapped DB causes to catch persistent storage issues."],"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"}