{"record":{"id":"a8d19f5e905df0b5","repo":"slimtoolkit/slim","slug":"no-layers","errorCode":null,"errorMessage":"no layers","messagePattern":"no layers","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/imagebuilder/internalbuilder/engine.go","lineNumber":58,"sourceCode":"\tpushToRegistry bool) (*Engine, error) {\n\n\tengine := &Engine{\n\t\tShowBuildLogs:  showBuildLogs,\n\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","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/imagebuilder/internalbuilder/engine.go#L40-L76","documentation":"Engine.Build assembles an image from the provided layer blobs/tarballs. With an empty Layers slice the resulting image would have no filesystem content, so Build fails fast with 'no layers' to avoid producing a broken or empty image.","triggerScenarios":"Calling engine.Build with SimpleBuildOptions.Layers of length 0 — e.g. layer archiving upstream produced nothing (empty source dir, all files filtered), or options were constructed without appending any layer entries.","commonSituations":"A COPY/collect step silently produced an empty directory that was then skipped; layer generation code filtered out every file (bad include patterns); config assembled programmatically with Layers forgotten while startup info was set.","solutions":["Populate options.Layers with at least one layer archive before calling Build; verify layer creation returned non-empty output.","Debug the upstream layer-generation code: check include/exclude globs and source paths so files are actually captured.","If a truly empty image is intended, use a builder path that allows it or add a minimal layer containing the runtime files."],"exampleFix":"// before\nopts := imagebuilder.SimpleBuildOptions{ImageConfig: cfg} // Layers empty\nres, err := engine.Build(opts) // no layers\n// after\nlayer, err := archive.TarWithOptions(appDir, &archive.TarOptions{})\nif err != nil { return err }\nopts := imagebuilder.SimpleBuildOptions{ImageConfig: cfg, Layers: []string{layerPath}}\nres, err := engine.Build(opts)","handlingStrategy":"validation","validationCode":"func hasLayers(opts imagebuilder.SimpleBuildOptions) bool {\n\treturn len(opts.Layers) > 0\n}\n\nif !hasLayers(opts) {\n\treturn errors.New(\"refusing to build: no layers were produced upstream\")\n}\nres, err := engine.Build(opts)","typeGuard":null,"tryCatchPattern":"res, err := engine.Build(opts)\nif err != nil {\n\tswitch {\n\tcase strings.Contains(err.Error(), \"no layers\"):\n\t\treturn nil, fmt.Errorf(\"layer generation produced nothing; check source dirs and include globs: %w\", err)\n\tcase strings.Contains(err.Error(), \"missing startup info\"):\n\t\treturn nil, fmt.Errorf(\"image config lacks CMD/ENTRYPOINT: %w\", err)\n\t}\n\treturn nil, err\n}","preventionTips":["Verify layer archiving output is non-empty before Build","Log layer counts at generation time to catch empty results early","Audit include/exclude patterns that can silently filter everything","Add a pre-build validator covering layers plus startup info"],"tags":["docker","image-builder","layers","validation"],"backgroundTag":"empty-image-layers","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}