slimtoolkit/slim · error

failed to prepare artifacts env: %w

Error message

failed to prepare artifacts env: %w

What it means

startMonitor first asks the artifactor to prepare the artifacts environment for the StartMonitor command. If artifactor.PrepareEnv(cmd) fails, the error is logged and wrapped with this message. Preparation includes creating directories, symlinks and device filtering via the helpers in artifact.go.

Source

Thrown at pkg/app/sensor/controlled/controlled.go:144

				return s.startMonitor(typedCmd)

			case *command.ShutdownSensor:
				return nil, nil // Clean exit

			default:
				log.Warn("sensor: ignoring unknown or unexpected command => ", cmd)
			} // eof: type switch

		case <-ticker.C:
			log.Debug(".")
		} // eof: select
	}
}

func (s *Sensor) startMonitor(cmd *command.StartMonitor) (monitor.CompositeMonitor, error) {
	if err := s.artifactor.PrepareEnv(cmd); err != nil {
		log.WithError(err).Error("sensor: artifactor.PrepareEnv() failed")
		return nil, 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 nil, 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

  1. Inspect the logged wrapped error from PrepareEnv for the root cause
  2. Verify the artifact output directories are writable and the mountPoint is correct
  3. Check disk space and permissions on the artifacts env paths
Defensive patterns

Strategy: validation

Validate before calling

// before starting monitor, ensure artifacts env is writable
for _, dir := range []string{artifactsDir, mountPoint} {
	if fi, err := os.Stat(dir); err != nil || !fi.IsDir() {
		log.Fatalf("invalid path %s: %v", dir, err)
	}
}

Try / catch

mon, err := startMonitor(cmd)
if err != nil && strings.Contains(err.Error(), "failed to prepare artifacts env") {
	log.Printf("env prep root cause: %v", errors.Unwrap(err))
}

Prevention

When it happens

Trigger: startMonitor is called (from runWithoutMonitor path) and PrepareEnv fails — e.g. cannot create artifact directories, stat helper errors (see errors 120/121), permission denied on mount point.

Common situations: Read-only or unwritable artifact paths, wrong mountPoint, disk full, non-Linux Sys() assertion failures during path enumeration.

Related errors


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