kubernetes/kops · error
error removing file %s: %w
Error message
error removing file %s: %w
What it means
Returned by MemFSPath.RemoveAll when deleting one of the paths gathered from ReadTree fails. The inner Remove on an in-memory path virtually never errors, so this guard fires only if the tree contains a path whose removal misbehaves — effectively an internal-consistency check while purging a memfs subtree.
Source
Thrown at util/pkg/vfs/memfs.go:200
func (p *MemFSPath) String() string {
return p.Path()
}
func (p *MemFSPath) Remove(ctx context.Context) error {
p.contents = nil
return nil
}
func (p *MemFSPath) RemoveAll(ctx context.Context) error {
tree, err := p.ReadTree(ctx)
if err != nil {
return err
}
for _, filePath := range tree {
err := filePath.Remove(ctx)
if err != nil {
return fmt.Errorf("error removing file %s: %w", filePath, err)
}
}
return nil
}
func (p *MemFSPath) RemoveAllVersions(ctx context.Context) error {
return p.Remove(ctx)
}
func (p *MemFSPath) Location() string {
return p.location
}
func (p *MemFSPath) IsPublic() (bool, error) {
if p.acl == nil {
return false, nil
}View on GitHub (pinned to 4c8573c808)
Solutions
- Inspect the wrapped error and offending path (%s/%w) to see which child failed and why
- Fix the ACL on the failing child path so Remove passes its permission check
- If idempotent cleanup is desired, tolerate not-exist errors: iterate the tree yourself and ignore vfs.ErrNotExist per child
Example fix
// before
tree, _ := dir.ReadTree(ctx)
for _, p := range tree { p.Remove(ctx) } // one failure aborts
// after
for _, p := range tree {
if err := p.Remove(ctx); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("error removing file %s: %w", p, err)
}
} Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
null
Try / catch
if err := dir.RemoveAll(ctx); err != nil {
var pe *pathError
klog.Warningf("partial RemoveAll: %v", err) // err names offending file and cause
} Prevention
- Ensure ACLs allow deletion of all descendants before RemoveAll
- Make cleanup idempotent: tolerate os.IsNotExist per child
- Log the wrapped path to repair partially deleted trees
When it happens
Trigger: Calling RemoveAll on a memfs directory where a child path's Remove fails (e.g. permission denied by the path's ACL during the ACL check performed by Remove).
Common situations: In-memory VFS used in tests/terraform rendering where an ACL restricts deletion of some descendant; partially deleted trees left behind after this error.
Related errors
- memfs path not recognized: %q
- memfs context not initialized
- error reading data: %v
- expected acl to be S3Acl, was %T
- reading data: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/ef117dad25b24bf3.
Report an issue: GitHub.