{"record":{"id":"daf3adb188be0ad5","repo":"slimtoolkit/slim","slug":"too-many-layers","errorCode":null,"errorMessage":"too many layers","messagePattern":"too many layers","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/imagebuilder/internalbuilder/engine.go","lineNumber":62,"sourceCode":"\t\tPushToDaemon:   pushToDaemon,\n\t\tPushToRegistry: pushToRegistry,\n\t}\n\n\treturn engine, nil\n}\n\nfunc (ref *Engine) Build(options imagebuilder.SimpleBuildOptions) (*imagebuilder.ImageResult, error) {\n\tif len(options.ImageConfig.Config.Entrypoint) == 0 &&\n\t\tlen(options.ImageConfig.Config.Cmd) == 0 {\n\t\treturn nil, fmt.Errorf(\"missing startup info\")\n\t}\n\n\tif len(options.Layers) == 0 {\n\t\treturn nil, fmt.Errorf(\"no layers\")\n\t}\n\n\tif len(options.Layers) > 255 {\n\t\treturn nil, fmt.Errorf(\"too many layers\")\n\t}\n\n\tswitch options.ImageConfig.Architecture {\n\tcase \"\":\n\t\toptions.ImageConfig.Architecture = \"amd64\"\n\tcase \"arm64\", \"amd64\":\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"bad architecture value\")\n\t}\n\n\tvar img v1.Image\n\tif options.From == \"\" {\n\t\t//same as FROM scratch\n\t\timg = empty.Image\n\t} else {\n\t\treturn nil, fmt.Errorf(\"custom base images are not supported yet\")\n\t}\n","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/imagebuilder/internalbuilder/engine.go#L44-L80","documentation":"Engine.Build rejects build options when more than 255 layer entries are supplied. OCI/Docker images have a practical layer-count limit and the builder enforces a hard cap of 255 to keep the produced image valid and buildable. If options.Layers contains 256 or more entries the build fails immediately before any image is created.","triggerScenarios":"Calling imagebuilder Engine.Build (via slim build) with SimpleBuildOptions.Layers containing >255 LayerDataInfo entries, e.g. when a large artifact set is expanded into one layer per file.","commonSituations":"Programmatic image generation that maps one artifact/file per layer instead of batching; scripts that accumulate layers in a loop without consolidation; large application bundles producing hundreds of tar/directory layers.","solutions":["Consolidate files into fewer tar archives so the Layers slice has 255 or fewer entries","Combine multiple directories into a single DirSource layer per logical root","Filter out unnecessary artifacts before building to reduce layer count","If the limit is genuinely blocking, raise the 255 cap in pkg/imagebuilder/internalbuilder/engine.go (validate against the target runtime first)"],"exampleFix":"// before\nfor _, f := range files {\n    layers = append(layers, imagebuilder.LayerDataInfo{Type: imagebuilder.TarSource, Source: f})\n}\n// after\n// batch files into archives so len(layers) <= 255\nbatch := tarBatch(files, 255)\nfor _, tarPath := range batch {\n    layers = append(layers, imagebuilder.LayerDataInfo{Type: imagebuilder.TarSource, Source: tarPath})\n}","handlingStrategy":"validation","validationCode":"if len(opts.Layers) > 255 {\n    return fmt.Errorf(\"build needs <=255 layers, got %d\", len(opts.Layers))\n}","typeGuard":null,"tryCatchPattern":"if _, err := engine.Build(opts); err != nil {\n    if strings.Contains(err.Error(), \"too many layers\") {\n        // consolidate layer sources and retry once\n    }\n    return err\n}","preventionTips":["Batch artifacts into a bounded number of tar layers before building","Assert len(Layers) <= 255 in build tooling tests","Consolidate per-file layers into per-directory layers"],"tags":["imagebuild","layers","limit","validation"],"backgroundTag":"too-many-layers","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}