slimtoolkit/slim · error
getDataType - error getting data type: %s / stderr: %s
Error message
getDataType - error getting data type: %s / stderr: %s
What it means
getDataType runs an external command (the 'file' type detector) and captures stdout/stderr. If cmd.Wait returns a non-zero exit, the function wraps both the exec error and the captured stderr into this message and returns it. It is the error path of detecting an artifact's data type from its content.
Source
Thrown at pkg/app/sensor/artifact/artifact.go:2829
hash := sha1.Sum(fileData)
return hex.EncodeToString(hash[:]), nil
}
func getDataType(artifactFileName string) (string, error) {
//TODO: use libmagic (pure impl)
var cerr bytes.Buffer
var cout bytes.Buffer
cmd := exec.Command(fileTypeCmd, artifactFileName)
cmd.Stderr = &cerr
cmd.Stdout = &cout
if err := cmd.Start(); err != nil {
return "", err
}
if err := cmd.Wait(); err != nil {
err = fmt.Errorf("getDataType - error getting data type: %s / stderr: %s", err, cerr.String())
return "", err
}
if typeInfo := strings.Split(strings.TrimSpace(cout.String()), ":"); len(typeInfo) > 1 {
return strings.TrimSpace(typeInfo[1]), nil
}
return "unknown", nil
}
/*
func cpFile(src, dst string) error {
s, err := os.Open(src)
if err != nil {
log.Warnln("sensor: monitor - cp - error opening source file =>", src)
return errView on GitHub (pinned to 81940d17fa)
Solutions
- Read the stderr portion of the message to see the detector's actual failure reason.
- Ensure the 'file' (or equivalent) command exists in the image and is on PATH.
- Verify the path being type-checked exists and is readable by the sensor user.
- Add a fallback that treats unknown type as a default (e.g. binary) instead of failing the whole artifact scan.
Example fix
// before
if err := cmd.Wait(); err != nil {
err = fmt.Errorf("getDataType - error getting data type: %s / stderr: %s", err, cerr.String())
return "", err
}
// after
if err := cmd.Wait(); err != nil {
log.Debugf("getDataType fallback for %s: %v / %s", path, err, cerr.String())
return "", fmt.Errorf("getDataType - error getting data type: %w / stderr: %s", err, cerr.String())
} Defensive patterns
Strategy: fallback
Validate before calling
if _, err := exec.LookPath(fileTypeCmd); err != nil {
return "", fmt.Errorf("type detector %q not on PATH: %w", fileTypeCmd, err)
}
if _, err := os.Stat(path); err != nil {
return "", fmt.Errorf("cannot type-check missing path %q: %w", path, err)
} Try / catch
dataType, err := getDataType(path)
if err != nil {
if strings.Contains(err.Error(), "getDataType - error getting data type") {
log.Warnf("type detection failed, assuming binary: %v", err)
dataType = "application/octet-stream" // fallback default
} else {
return err
}
} Prevention
- Include the file(1) utility in container images used for artifact scanning
- Set PATH explicitly in the sensor's execution environment
- Verify the target file exists before invoking the detector
When it happens
Trigger: The type-detection command exits non-zero: the 'file' binary is missing in the container image, the analyzed path does not exist or is unreadable, or the command is killed (OOM/signals).
Common situations: Minimal distroless container images lacking the file(1) utility; analyzing a file that was deleted mid-scan; PATH not set in the sensor's execution environment.
Related errors
AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31).
Data as JSON: /api/errors/c0e3beba79c057b9.
Report an issue: GitHub.