{"record":{"id":"169b18f8661245a1","repo":"slimtoolkit/slim","slug":"error-waiting-for-sensor-event-w","errorCode":null,"errorMessage":"error waiting for sensor event: %w","messagePattern":"error waiting for sensor event: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/sensor/app.go","lineNumber":321,"sourceCode":"func runControlCommand(ctx context.Context) error {\n\tif len(os.Args) < 3 {\n\t\treturn errors.New(\"missing command\")\n\t}\n\n\tcmd := control.Command(os.Args[2])\n\n\tswitch cmd {\n\tcase control.StopTargetAppCommand:\n\t\tif err := control.ExecuteStopTargetAppCommand(ctx, *commandsFile); err != nil {\n\t\t\treturn fmt.Errorf(\"error stopping target app: %w\", err)\n\t\t}\n\n\tcase control.WaitForEventCommand:\n\t\tif len(os.Args) < 4 {\n\t\t\treturn errors.New(\"missing event name\")\n\t\t}\n\t\tif err := control.ExecuteWaitEvenCommand(ctx, eventsFilePath(), event.Type(os.Args[3])); err != nil {\n\t\t\treturn fmt.Errorf(\"error waiting for sensor event: %w\", err)\n\t\t}\n\n\tdefault:\n\t\treturn fmt.Errorf(\"unknown command: %s\", cmd)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":303,"sourceCodeEnd":330,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/sensor/app.go#L303-L330","documentation":"In runControlCommand, the 'wait-for-event' control command calls control.ExecuteWaitEvenCommand to block until the named event is received through the events file. If that wait fails (file I/O error, timeout, malformed event stream), the error is wrapped as 'error waiting for sensor event' and returned from Run.","triggerScenarios":"Running the sensor with the WaitForEventCommand and an event name from os.Args[3] while ExecuteWaitEvenCommand fails — events file cannot be created/read, the expected event never arrives before the context is cancelled, or the event type is invalid.","commonSituations":"Context deadline exceeded because the target app never emitted the event; events file directory deleted or read-only; typo in the event name so the sensor waits forever then times out.","solutions":["Check the wrapped inner error to distinguish file errors from timeouts.","Confirm the events file path (eventsFilePath()) points to a writable, existing directory.","Verify the event name (os.Args[3]) exactly matches an event the target app emits.","Increase the context timeout if the event legitimately takes long to fire."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if len(os.Args) < 4 {\n    return errors.New(\"missing event name\")\n}\nif _, err := os.Stat(filepath.Dir(eventsFilePath())); err != nil {\n    return fmt.Errorf(\"events dir missing: %w\", err)\n}","typeGuard":"func isValidEventType(name string) bool {\n    _, ok := event.TypeFromString(name) // or membership check in known events\n    return ok\n}","tryCatchPattern":"err := app.Run(ctx)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) && strings.Contains(err.Error(), \"waiting for sensor event\") {\n        return fmt.Errorf(\"event %q never arrived within deadline; check event name and emitter\", os.Args[3])\n    }\n    return err\n}","preventionTips":["Match event names exactly against the event.Type constants the target emits","Pre-create the events directory with correct permissions","Set a generous but bounded context deadline for the wait"],"tags":["events","sensor","cli","timeout"],"backgroundTag":"event-wait-failed","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}