anomalyco/sst · error
failed to flatten %s structure: %w
Error message
failed to flatten %s structure: %w
What it means
During workspace-layout flattening of a Python package (moving a src/ layout to the bundle root), any failure from copyDir or copyFile is wrapped as "failed to flatten %s structure" with the package name. The library flattens workspace packages so imports resolve at the bundle root; this error means one of the package's files/directories could not be copied during that step.
Source
Thrown at pkg/runtime/python/python.go:541
continue
}
for _, innerEntry := range innerEntries {
if isIgnored(innerEntry.Name()) {
continue
}
srcPath := filepath.Join(innerPackageDir, innerEntry.Name())
destPath := filepath.Join(packageDir, innerEntry.Name())
if innerEntry.IsDir() {
err = copyDir(srcPath, destPath, skipContent)
} else {
err = copyFile(srcPath, destPath)
}
if err != nil {
return fmt.Errorf("failed to flatten %s structure: %w", packageName, err)
}
}
// Remove the old src/ directory after flattening to avoid import confusion
if err := os.RemoveAll(srcDir); err != nil {
slog.Warn("failed to remove src/ after flattening", "package", packageName, "error", err)
}
}
}
return nil
}
// Check top-level directories
if err := flattenDir(artifactDir); err != nil {
return err
}
View on GitHub (pinned to a0bd20f762)
Solutions
- Inspect the wrapped inner error to see which file failed; fix that specific path (permissions, missing dir)
- Remove stale files at the bundle root that conflict with the flattened layout
- Clean the .sst build output and redeploy for a fresh copy
- Check disk space and that source package files are all readable
Defensive patterns
Strategy: try-catch
Validate before calling
null
Try / catch
if err := sstBuild(); err != nil {
if strings.Contains(err.Error(), "failed to flatten") {
var pkg string
fmt.Sscanf(err.Error(), "failed to flatten %s structure", &pkg)
// inspect that package's src layout and permissions, clean output, rebuild
}
} Prevention
- Clean stale .sst build output before restructuring workspace packages
- Ensure bundle output dirs are writable and empty of conflicting files
- Keep package sources readable (no restrictive modes/symlink loops)
- Watch disk space when flattening large packages
When it happens
Trigger: While flattening a workspace package, copyDir(srcPath, destPath, skipContent) or copyFile(srcPath, destPath) returns an error — destination directory missing/unwritable, source unreadable, or disk full. The package name is interpolated into the message.
Common situations: Monorepo Python package with a src/ layout and a conflicting file already at the bundle root; read-only bundle directory; package containing symlinks or unreadable files; insufficient disk space during a large package copy.
Related errors
- failed to open archive: %w
- failed to remove old directory: %w
- failed to move src directory contents: %w
- failed to rename directory: %w
- failed to read source directory: %w
AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30).
Data as JSON: /api/errors/c34feb5f183a96cd.
Report an issue: GitHub.