slimtoolkit/slim · error

cannot create execution - cannot read command file %q: %w

Error message

cannot create execution - cannot read command file %q: %w

What it means

NewStandalone reads the sensor's start command (a command.StartMonitor JSON) from commandFileName via readCommandFile. Any failure reading that file (missing, unreadable, I/O error) is surfaced as this wrapped error, aborting execution creation.

Source

Thrown at pkg/app/sensor/execution/standalone.go:52

	// fsutil.Touch() creates (potentially missing) folder(s).
	if err := fsutil.Touch(eventFileName); err != nil {
		return nil, fmt.Errorf(
			"cannot create execution - touch event file %q failed: %w",
			eventFileName, err,
		)
	}

	eventFile, err := os.OpenFile(eventFileName, os.O_APPEND|os.O_WRONLY|os.O_SYNC, 0644)
	if err != nil {
		return nil, fmt.Errorf(
			"cannot create execution - open event file %q failed: %w",
			eventFileName, err,
		)
	}

	cmd, err := readCommandFile(commandFileName)
	if err != nil {
		return nil, fmt.Errorf(
			"cannot create execution - cannot read command file %q: %w",
			commandFileName, err,
		)
	}

	commandCh := make(chan command.Message, 10)
	commandCh <- &cmd

	go control.HandleControlCommandQueue(ctx, commandFileName, commandCh)

	return &standaloneExe{
		hookExecutor: hookExecutor{
			ctx: ctx,
			cmd: lifecycleHookCommand,
		},
		commandCh: commandCh,
		eventFile: eventFile,
	}, nil

View on GitHub (pinned to 81940d17fa)

Solutions

  1. Verify commandFileName exists and is readable (ls -l) before starting the sensor.
  2. Ensure the volume containing the command file is mounted into the sensor container at the expected path.
  3. Fix the underlying error in the wrapped %w message (permissions, ENOENT, etc.).

Example fix

// before
iface, err := execution.NewStandalone("/missing/cmd", eventFile, hook)
// after
// mount the command file first, then:
iface, err := execution.NewStandalone("/var/run/sensor/cmd", eventFile, hook)
Defensive patterns

Strategy: validation

Validate before calling

func commandFileReady(path string) error {
    fi, err := os.Stat(path)
    if err != nil { return fmt.Errorf("command file missing: %w", err) }
    if fi.Size() == 0 { return fmt.Errorf("command file empty") }
    f, err := os.Open(path)
    if err != nil { return err }
    return f.Close()
}

Type guard

func isMissingFileError(err error) bool {
    return errors.Is(err, fs.ErrNotExist)
}

Try / catch

exec, err := execution.NewStandalone(commandFile, eventFile, hook)
if err != nil && strings.Contains(err.Error(), "cannot read command file") {
    return fmt.Errorf("sensor startup aborted, command file unreadable: %w", err)
}

Prevention

When it happens

Trigger: Calling NewStandalone with a commandFileName that does not exist, is unreadable by the current user, or cannot be read due to I/O errors (e.g. missing volume mount).

Common situations: The instrumentor was supposed to write the command file into a shared volume that was not mounted; command file deleted before the sensor started; wrong path passed to newExecution.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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