{"record":{"id":"c34feb5f183a96cd","repo":"anomalyco/sst","slug":"failed-to-flatten-s-structure-w","errorCode":null,"errorMessage":"failed to flatten %s structure: %w","messagePattern":"failed to flatten (.+?) structure: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/runtime/python/python.go","lineNumber":541,"sourceCode":"\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tfor _, innerEntry := range innerEntries {\n\t\t\t\t\tif isIgnored(innerEntry.Name()) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tsrcPath := filepath.Join(innerPackageDir, innerEntry.Name())\n\t\t\t\t\tdestPath := filepath.Join(packageDir, innerEntry.Name())\n\n\t\t\t\t\tif innerEntry.IsDir() {\n\t\t\t\t\t\terr = copyDir(srcPath, destPath, skipContent)\n\t\t\t\t\t} else {\n\t\t\t\t\t\terr = copyFile(srcPath, destPath)\n\t\t\t\t\t}\n\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"failed to flatten %s structure: %w\", packageName, err)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Remove the old src/ directory after flattening to avoid import confusion\n\t\t\t\tif err := os.RemoveAll(srcDir); err != nil {\n\t\t\t\t\tslog.Warn(\"failed to remove src/ after flattening\", \"package\", packageName, \"error\", err)\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t\treturn nil\n\t}\n\n\t// Check top-level directories\n\tif err := flattenDir(artifactDir); err != nil {\n\t\treturn err\n\t}\n","sourceCodeStart":523,"sourceCodeEnd":559,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/runtime/python/python.go#L523-L559","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"null","typeGuard":null,"tryCatchPattern":"if err := sstBuild(); err != nil {\n\tif strings.Contains(err.Error(), \"failed to flatten\") {\n\t\tvar pkg string\n\t\tfmt.Sscanf(err.Error(), \"failed to flatten %s structure\", &pkg)\n\t\t// inspect that package's src layout and permissions, clean output, rebuild\n\t}\n}","preventionTips":["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"],"tags":["go","filesystem","python","packaging"],"backgroundTag":"package-flatten-failed","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}