{"record":{"id":"da7fe042df07d4eb","repo":"slimtoolkit/slim","slug":"unexpected-start-monitor-command-v","errorCode":null,"errorMessage":"unexpected start monitor command: %+v","messagePattern":"unexpected start monitor command: %\\+v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/sensor/standalone/standalone.go","lineNumber":118,"sourceCode":"func (s *Sensor) run() error {\n\traw := <-s.exe.Commands()\n\tcmd, ok := (raw).(*command.StartMonitor)\n\tif !ok {\n\t\tlog.\n\t\t\tWithField(\"cmd\", fmt.Sprintf(\"%+v\", cmd)).\n\t\t\tError(\"sensor: unexpected start monitor command\")\n\t\ts.exe.HookMonitorFailed()\n\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.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)","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/sensor/standalone/standalone.go#L100-L136","documentation":"The standalone sensor's run loop received a StartMonitor command whose content it did not expect (wrong command type or malformed cmd payload), after publishing a StateCmdStartMonCmdWaiting event. The library throws this to abort processing of an unrecognized start-monitor command instead of proceeding with PrepareEnv. The %+v dump of cmd in the message shows exactly what was received.","triggerScenarios":"The control server sends a raw command whose GetName() does not match a supported start-monitor command type, so the switch/state-machine in run() falls through to the error return with the unexpected cmd struct.","commonSituations":"Version mismatch between the controller/orchestrator sending commands and the sensor binary; a corrupted or hand-crafted control payload; wiring the wrong command type through the cmd server during development.","solutions":["Read the %+v dump in the error and compare cmd.GetName()/fields against the supported command types in the sensor.","Upgrade or align the controller and sensor versions so both agree on the start-monitor command schema.","Fix the caller that enqueues the command to emit the correct command type.","If reproducing in tests, construct the command using the sensor's own command constructors instead of raw values."],"exampleFix":"// before\n// controller sends an ad-hoc command type\nraw := command.New(\"start-mon\", payload) // unknown to sensor\n// after\nraw := command.New(command.TypeStartMonitor, payload) // use supported type","handlingStrategy":"validation","validationCode":"switch raw.GetName() {\ncase command.TypeStartMonitor:\n    // supported\ndefault:\n    return fmt.Errorf(\"controller bug: unsupported command %q\", raw.GetName())\n}","typeGuard":null,"tryCatchPattern":"if err := sensor.Run(ctx); err != nil {\n    var unexpectedCmd interface{ Error() string }\n    if strings.Contains(err.Error(), \"unexpected start monitor command\") {\n        log.Errorf(\"protocol mismatch, payload: %s\", err.Error())\n    }\n    return err\n}","preventionTips":["Keep controller and sensor on the same version so command schemas match.","Only construct commands via the shared command package constructors.","Log raw.GetName() on receipt to catch protocol drift early.","Add a contract test asserting the emitted command type is recognized by the sensor."],"tags":["go","sensor","command-dispatch","protocol"],"backgroundTag":"unexpected-command-type","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}