slimtoolkit/slim · error
failed to prepare artifacts env: %w
Error message
failed to prepare artifacts env: %w
What it means
Wraps an error returned by s.artifactor.PrepareEnv(cmd) during the standalone sensor's start-monitor flow. PrepareEnv sets up the artifact environment (directories, mounts, excludes) needed for monitoring; when that setup fails (I/O error, permission problem, invalid command parameters), run() publishes a StartMonitorFailed event and returns this wrapped error.
Source
Thrown at pkg/app/sensor/standalone/standalone.go:130
State: event.StateCmdStartMonCmdWaiting,
Context: map[string]string{
event.CtxCmdType: string(raw.GetName()),
},
})
return fmt.Errorf("unexpected start monitor command: %+v", cmd)
}
if err := s.artifactor.PrepareEnv(cmd); err != nil {
log.WithError(err).Error("sensor: artifactor.PrepareEnv() failed")
s.exe.HookMonitorFailed()
s.exe.PubEvent(event.StartMonitorFailed,
&event.StartMonitorFailedData{
Component: event.ComSensorCmdServer,
State: event.StateEnvPreparing,
Errors: []string{err.Error()},
})
return fmt.Errorf("failed to prepare artifacts env: %w", err)
}
origPaths, err := s.artifactor.GetCurrentPaths(s.mountPoint, cmd.Excludes)
if err != nil {
log.WithError(err).Error("sensor: artifactor.GetCurrentPaths() failed")
return fmt.Errorf("failed to enumerate current paths: %w", err)
}
s.exe.HookMonitorPreStart()
mon, err := s.newMonitor(
s.ctx,
cmd,
s.workDir,
s.del,
s.artifactor.ArtifactsDir(),
s.mountPoint,
origPaths,View on GitHub (pinned to 81940d17fa)
Solutions
- Check the wrapped error and the sensor log line 'sensor: artifactor.PrepareEnv() failed' for the root cause.
- Verify the artifacts directory/mount point exists and is writable by the sensor process.
- Validate the StartMonitor command's fields (paths/excludes) are correct for your environment.
- Ensure sufficient disk space and correct container capabilities/mounts when running in containers.
Example fix
// before (docker run without writable volume) docker run --rm sensor-image // after docker run --rm -v /path/to/artifacts:/artifacts:rw sensor-image
Defensive patterns
Strategy: validation
Validate before calling
if err := os.MkdirAll(artifactsDir, 0o755); err != nil {
log.Fatalf("artifacts dir not creatable: %v", err)
}
if f, err := os.CreateTemp(artifactsDir, ".probe"); err != nil {
log.Fatalf("artifacts dir not writable: %v", err)
} else {
f.Close(); os.Remove(f.Name())
} Try / catch
if err := sensor.Run(ctx); err != nil {
if strings.Contains(err.Error(), "failed to prepare artifacts env") {
log.Errorf("check mounts/permissions for artifacts dir: %v", err)
}
return err
} Prevention
- Mount the artifacts directory read-write in containers before starting the sensor.
- Pre-create the artifacts directory with correct ownership for the sensor user.
- Monitor disk space on the artifacts volume.
- Validate StartMonitor command fields (paths/excludes) in tests before deployment.
When it happens
Trigger: Calling run()/start-monitor when artifactor.PrepareEnv fails: e.g. the artifacts directory cannot be created, the mount point is invalid, the underlying cmd path is read-only, or cmd parameters (excludes/paths) are invalid.
Common situations: Running the sensor in a container without write access to the artifacts location; mount point not existing or not being mounted; disk full; misconfigured excludes causing path setup failures.
Related errors
- failed to enumerate current paths: %w
- failed to enumerate current paths: %w
- saving reports failed: %w
- sensor shutdown before monitor stop
- ambiguous start command: cannot use [app_name,app_args] and
AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31).
Data as JSON: /api/errors/7c0ac5dba7b04484.
Report an issue: GitHub.