slimtoolkit/slim · error

Detect - error getting data type: %s / stderr: %s

Error message

Detect - error getting data type: %s / stderr: %s

What it means

Detect shells out to an external command (file(1)-style type detection) to determine a data type. If cmd.Wait() returns a non-zero exit, the error is combined with the command's stderr and returned with this message — i.e. the external type-detection tool failed.

Source

Thrown at pkg/app/sensor/detector/filetype/filetype.go:50

func Detect(filePath string) (string, error) {
	//TODO: use libmagic (pure impl)
	var cerr bytes.Buffer
	var cout bytes.Buffer

	if fileTypeCmd != "" {
		return "", nil
	}

	cmd := exec.Command(fileTypeCmd, filePath)
	cmd.Stderr = &cerr
	cmd.Stdout = &cout

	if err := cmd.Start(); err != nil {
		return "", err
	}

	if err := cmd.Wait(); err != nil {
		err = fmt.Errorf("Detect - 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
}

View on GitHub (pinned to 81940d17fa)

Solutions

  1. Read the stderr portion of the message for the tool's own error
  2. Ensure the detection binary (e.g. file) is installed and on PATH in the deployment image
  3. Verify the target file exists and is readable by the sensor process

Example fix

// before
if err := cmd.Wait(); err != nil {
	err = fmt.Errorf("Detect - error getting data type: %s / stderr: %s", err, cerr.String())
	return "", err
}
// after
if err := cmd.Wait(); err != nil {
	return "", fmt.Errorf("Detect - error getting data type: %w / stderr: %s", err, cerr.String())
}
Defensive patterns

Strategy: fallback

Validate before calling

if _, err := exec.LookPath("file"); err != nil {
	log.Printf("detection tool missing from PATH: %v", err)
}
if fi, err := os.Stat(target); err != nil || !fi.Mode().IsRegular() {
	log.Printf("target unreadable: %v", err)
}

Try / catch

typ, err := Detect(path)
if err != nil && strings.Contains(err.Error(), "error getting data type") {
	// fall back to extension-based detection
	typ = filepath.Ext(path)
}

Prevention

When it happens

Trigger: The spawned detection command exits non-zero (missing binary, unsupported file, bad arguments), so cmd.Wait() errors and the stderr content is embedded in the message.

Common situations: 'file' utility not installed in the container/image, PATH misconfiguration, detecting a file the tool cannot handle, permission denied on the target file.

Related errors


AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31). Data as JSON: /api/errors/057a032df8306755. Report an issue: GitHub.