{"record":{"id":"761827048b26a429","repo":"slimtoolkit/slim","slug":"cannot-create-execution-touch-event-file-q-fail","errorCode":null,"errorMessage":"cannot create execution - touch event file %q failed: %w","messagePattern":"cannot create execution - touch event file %q failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/sensor/execution/standalone.go","lineNumber":36,"sourceCode":"\t\"github.com/slimtoolkit/slim/pkg/util/fsutil\"\n)\n\ntype standaloneExe struct {\n\thookExecutor\n\n\tcommandCh chan command.Message\n\teventFile io.WriteCloser\n}\n\nfunc NewStandalone(\n\tctx context.Context,\n\tcommandFileName string,\n\teventFileName string,\n\tlifecycleHookCommand string,\n) (Interface, error) {\n\t// fsutil.Touch() creates (potentially missing) folder(s).\n\tif err := fsutil.Touch(eventFileName); err != nil {\n\t\treturn nil, fmt.Errorf(\n\t\t\t\"cannot create execution - touch event file %q failed: %w\",\n\t\t\teventFileName, err,\n\t\t)\n\t}\n\n\teventFile, err := os.OpenFile(eventFileName, os.O_APPEND|os.O_WRONLY|os.O_SYNC, 0644)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\n\t\t\t\"cannot create execution - open event file %q failed: %w\",\n\t\t\teventFileName, err,\n\t\t)\n\t}\n\n\tcmd, err := readCommandFile(commandFileName)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\n\t\t\t\"cannot create execution - cannot read command file %q: %w\",\n\t\t\tcommandFileName, err,","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/sensor/execution/standalone.go#L18-L54","documentation":"NewStandalone builds a standalone execution that streams events to an event file and reads its start command from a command file. Before anything else it calls fsutil.Touch(eventFileName) which creates the event file and any missing parent directories. If that touch fails (unwritable path, permission denied, invalid path, read-only filesystem), the execution cannot be created and this wrapped error is returned.","triggerScenarios":"Calling NewStandalone (via newExecution) with an eventFileName whose parent directory cannot be created or written: missing permissions, read-only mount, invalid characters in path, or disk errors.","commonSituations":"Container running as non-root user without write access to the mount path; event file directory not mounted/volume not provisioned; SELinux/AppArmor blocking file creation; typo in the configured events path.","solutions":["Check the wrapped error (%w) to see the underlying fs failure and fix the root cause (permissions, missing mount, bad path).","Ensure the parent directory of eventFileName exists and is writable by the sensor process user (chown/chmod or mount a writable volume).","Verify the filesystem is not read-only (e.g. container rootfs mounted ro) and point the event file to a writable path."],"exampleFix":"// before\niface, err := execution.NewStandalone(\"/cmd\", \"/nonexistent/events.sock\", hook)\n// after\nos.MkdirAll(\"/var/run/sensor\", 0755) // ensure writable dir\niface, err := execution.NewStandalone(\"/cmd\", \"/var/run/sensor/events.sock\", hook)","handlingStrategy":"validation","validationCode":"func canCreate(path string) error {\n    dir := filepath.Dir(path)\n    if fi, err := os.Stat(dir); err != nil {\n        return err\n    } else if !fi.IsDir() {\n        return fmt.Errorf(\"%s is not a directory\", dir)\n    }\n    f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644)\n    if err != nil { return err }\n    return f.Close()\n}","typeGuard":"func isPathWritableError(err error) bool {\n    return errors.Is(err, os.ErrPermission) || errors.Is(err, syscall.EROFS) || errors.Is(err, syscall.ENOENT)\n}","tryCatchPattern":"exec, err := execution.NewStandalone(cmdFile, eventFile, hook)\nif err != nil && strings.Contains(err.Error(), \"touch event file\") {\n    log.Fatalf(\"event file path unusable: %v\", err) // fix perms/mount before retry\n}","preventionTips":["Create the event file's parent directory with os.MkdirAll in init or entrypoint scripts.","Mount a writable volume (emptyDir) for runtime files instead of using the container rootfs.","Run the sensor with a user that owns the runtime directory.","Pre-flight check fsutil.Touch on the path before calling NewStandalone."],"tags":["filesystem","file-creation","permissions","standalone-execution"],"backgroundTag":"file-permission-denied","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}