slimtoolkit/slim · error
unknown image data source - %v
Error message
unknown image data source - %v
What it means
The layer Type switch only accepts imagebuilder.TarSource and imagebuilder.DirSource; any other value hits the default branch and aborts with this error. Notably the message prints layerInfo.Source (not the Type), so the printed value may look odd — the real problem is an unrecognized Type constant.
Source
Thrown at pkg/imagebuilder/internalbuilder/engine.go:192
layer, err := layerFromTar(layerInfo)
if err != nil {
return nil, err
}
layersToAdd = append(layersToAdd, layer)
case imagebuilder.DirSource:
if !fsutil.IsDir(layerInfo.Source) {
return nil, fmt.Errorf("image layer data source path is not a directory - %s", layerInfo.Source)
}
layer, err := layerFromDir(layerInfo)
if err != nil {
return nil, err
}
layersToAdd = append(layersToAdd, layer)
default:
return nil, fmt.Errorf("unknown image data source - %v", layerInfo.Source)
}
}
log.Debug("DefaultSimpleBuilder.Build: adding layers to image")
newImg, err := mutate.AppendLayers(img, layersToAdd...)
if err != nil {
return nil, err
}
if len(options.Tags) == 0 {
return nil, fmt.Errorf("missing tags")
}
tag, err := name.NewTag(options.Tags[0])
if err != nil {
return nil, err
}
View on GitHub (pinned to 81940d17fa)
Solutions
- Set Type to imagebuilder.TarSource or imagebuilder.DirSource explicitly for every layer
- Check for zero-value LayerDataInfo structs missing Type initialization
- Always use the exported constants rather than literal strings
- If the message value is a valid path, inspect the Type field — the error prints Source, not Type
Example fix
// before
layers = append(layers, imagebuilder.LayerDataInfo{Source: "/tmp/rootfs"}) // Type is zero value
// after
layers = append(layers, imagebuilder.LayerDataInfo{Type: imagebuilder.DirSource, Source: "/tmp/rootfs"}) Defensive patterns
Strategy: validation
Validate before calling
for i, l := range opts.Layers {
switch l.Type {
case imagebuilder.TarSource, imagebuilder.DirSource:
default:
return fmt.Errorf("layer %d has unknown Type %q", i, l.Type)
}
} Try / catch
if _, err := engine.Build(opts); err != nil {
if strings.Contains(err.Error(), "unknown image data source") {
// inspect each layer's Type; note the error prints Source, not Type
}
return err
} Prevention
- Always initialize LayerDataInfo.Type with the exported constants
- Avoid constructing LayerDataInfo as a bare zero-value struct literal
- Add a pre-build sweep that rejects layers with empty/unknown Type
When it happens
Trigger: Setting LayerDataInfo.Type to an undefined/zero value, a type from a different package, or a custom string; constructing LayerDataInfo without initializing Type.
Common situations: Zero-value structs (Type "") where Source was set but Type forgotten; renaming or hand-writing type strings instead of using imagebuilder.TarSource/DirSource constants; version drift between producer and builder code.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- too many layers
- empty image layer data source
- image layer data source path is not a tar file - %s
- no layers
- bad architecture value
AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31).
Data as JSON: /api/errors/a809caf6e09cbc67.
Report an issue: GitHub.