{"record":{"id":"7c0ac5dba7b04484","repo":"slimtoolkit/slim","slug":"failed-to-prepare-artifacts-env-w-7c0ac5","errorCode":null,"errorMessage":"failed to prepare artifacts env: %w","messagePattern":"failed to prepare artifacts env: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/sensor/standalone/standalone.go","lineNumber":130,"sourceCode":"\t\t\t\tState:     event.StateCmdStartMonCmdWaiting,\n\t\t\t\tContext: map[string]string{\n\t\t\t\t\tevent.CtxCmdType: string(raw.GetName()),\n\t\t\t\t},\n\t\t\t})\n\n\t\treturn fmt.Errorf(\"unexpected start monitor command: %+v\", cmd)\n\t}\n\n\tif err := s.artifactor.PrepareEnv(cmd); err != nil {\n\t\tlog.WithError(err).Error(\"sensor: artifactor.PrepareEnv() failed\")\n\t\ts.exe.HookMonitorFailed()\n\t\ts.exe.PubEvent(event.StartMonitorFailed,\n\t\t\t&event.StartMonitorFailedData{\n\t\t\t\tComponent: event.ComSensorCmdServer,\n\t\t\t\tState:     event.StateEnvPreparing,\n\t\t\t\tErrors:    []string{err.Error()},\n\t\t\t})\n\t\treturn fmt.Errorf(\"failed to prepare artifacts env: %w\", err)\n\t}\n\n\torigPaths, err := s.artifactor.GetCurrentPaths(s.mountPoint, cmd.Excludes)\n\tif err != nil {\n\t\tlog.WithError(err).Error(\"sensor: artifactor.GetCurrentPaths() failed\")\n\t\treturn fmt.Errorf(\"failed to enumerate current paths: %w\", err)\n\t}\n\n\ts.exe.HookMonitorPreStart()\n\n\tmon, err := s.newMonitor(\n\t\ts.ctx,\n\t\tcmd,\n\t\ts.workDir,\n\t\ts.del,\n\t\ts.artifactor.ArtifactsDir(),\n\t\ts.mountPoint,\n\t\torigPaths,","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/sensor/standalone/standalone.go#L112-L148","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (docker run without writable volume)\ndocker run --rm sensor-image\n// after\ndocker run --rm -v /path/to/artifacts:/artifacts:rw sensor-image","handlingStrategy":"validation","validationCode":"if err := os.MkdirAll(artifactsDir, 0o755); err != nil {\n    log.Fatalf(\"artifacts dir not creatable: %v\", err)\n}\nif f, err := os.CreateTemp(artifactsDir, \".probe\"); err != nil {\n    log.Fatalf(\"artifacts dir not writable: %v\", err)\n} else {\n    f.Close(); os.Remove(f.Name())\n}","typeGuard":null,"tryCatchPattern":"if err := sensor.Run(ctx); err != nil {\n    if strings.Contains(err.Error(), \"failed to prepare artifacts env\") {\n        log.Errorf(\"check mounts/permissions for artifacts dir: %v\", err)\n    }\n    return err\n}","preventionTips":["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."],"tags":["go","sensor","filesystem","environment-setup"],"backgroundTag":"environment-setup-failed","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}