{"record":{"id":"810f8a743f254e1c","repo":"hashicorp/nomad","slug":"unable-to-determine-service-state-w","errorCode":null,"errorMessage":"unable to determine service state - %w","messagePattern":"unable to determine service state - %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/windows_service_install.go","lineNumber":149,"sourceCode":"\t// Check if the nomad service has already been\n\t// registered. If so the service needs to be\n\t// stopped before proceeding with the install.\n\texists, err := m.IsServiceRegistered(winsvc.WINDOWS_SERVICE_NAME)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to check for existing service - %w\", err)\n\t}\n\n\tif exists {\n\t\tnmdSvc, err := m.GetService(winsvc.WINDOWS_SERVICE_NAME)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not get existing service to stop - %w\", err)\n\t\t}\n\n\t\t// If the service is running and the reinstall\n\t\t// option was not set, return an error\n\t\trunning, err := nmdSvc.IsRunning()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to determine service state - %w\", err)\n\t\t}\n\t\tif running && !opts.reinstall {\n\t\t\treturn fmt.Errorf(\"service is already running. Please run the\\ncommand again with -reinstall to stop the service and install.\")\n\t\t}\n\n\t\tif running {\n\t\t\tc.Ui.Output(\"  Stopping existing nomad service\")\n\t\t\tif err := nmdSvc.Stop(); err != nil {\n\t\t\t\treturn fmt.Errorf(\"unable to stop existing service - %w\", err)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Install the nomad binary into the system\n\tif err = c.binaryInstall(opts); err != nil {\n\t\treturn fmt.Errorf(\"binary install failed - %w\", err)\n\t}\n","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/windows_service_install.go#L131-L167","documentation":"Fires in performInstall when querying the state of the existing Nomad Windows service (IsRunning) fails, so the installer cannot tell whether the service must be stopped before reinstalling.","triggerScenarios":"Thrown at command/windows_service_install.go:149 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check service state manually with sc query <service>","Re-run elevated if the query was access-denied","Stop the service manually then retry with -reinstall"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}